Back in DirectX 8.0 (or it might have been 9.0, I can never remember), Microsoft introduced a new feature into DirectInput called Action Mapping. In theory it was suppose to fix all of our problems when it came to interacting with the user. In reality it never really worked out and wasn't extremely popular, it was used just not nearly as popular as say HLSL.
The main problem with the implementation that Microsoft gave us was two fold. First, it wasn't that flexible and the second problem was that it simply wasn't that easy to use (much more complicated than it needed to be). However the concept as a whole is rather solid: We have events that we want to do when a specific state is reached (when a specific key or set of keys are down). Instead of constantly polling to see if that state is reached, we let the system do it. The system then calls the events for us. Basically it allows for an event driven architecture.
I've decided to use this concept, although tweaked, within the Lunar Engine. The input system is a little too large for me to post here on the page so I've added it as a zip file:
InputManager.zip (3.71 kb)
I've commented the functions, etc. so you should be able to figure it out. I will note though that it does use the Lunar Engine's main object to initiate some things as well as hook itself up. Also note that for the backbone I'm using Mogre's version of OIS. It seems to work well and I didn't want to bother with wrapping my old DirectInput code. As I've gotten older I've noticed I've become a lot lazier in that regard.
To setup our own mappings we simply use code similar to the following:
//Create the list of keys we want to associate with the action
List<KeyCode> KeyCodes=new List<KeyCode>();
KeyCodes.Add(KeyCode.KC_ESCAPE);
//Create the action itself
ActionMapping EndProgramAction=new LunarEngine.Input.ActionMapping("EndProgram", //The name of the action
KeyCodes,
new EventHandler<LunarEngine.Input.InputEventArgs>(Escape_Event)) //The event to call
//Add the action to the list that the engine uses
Engine.Input.Mappings.Add(EndProgramAction);
And the engine takes care of the rest. Anyway, download the file and view the system. It's a very basic implementation that just matches up a set of keys (or mouse movement) to an event and that's about it but it does show you how to set up a similar system within your own game. There are more complicated implementations that I've seen including one here. However I've always felt that a simpler approach would work better. What about you, what are your experiences with action mapping? Suggestions for improvement?