That is the messaging system from my project. It is not necessary good for everything, I just wanted to make my input platform-independent. The idea is to use Context-Receiver scheme.
virtual void onKeyDown(unsigned short key, unsigned rep)=0;
virtual void onKeyUp(unsigned short key, unsigned rep)=0;
virtual void onMouseDown(int x, int y, unsigned button)=0;
virtual void update()=0;
virtual Receiver* setTargetReceiver(Receiver* tr)=0;
virtual void sendMessage(Message mes)=0;
The system proved to be good for aboth ssinchronous and synchronous events handling.
The framework installs Context.
User adds custom Receiver to Context.
The system scans hardware when updates and sends corresponding messages to the Receiver.
User can send own messages through sendMessage function.
Context-Receiver pairs can be written for most subsystems. The code above is just the example of doing it for input.
Maybe that helps.