Skip to main content
gamedev.net
🔒 Locked

Input Action Mapping

Started by Samurai Jack Feb 27, 2007 at 1:42 AM 4 replies 2.2k views
Original Post
Samurai Jack
Samurai Jack
Greetings! In my game application I use several methods to gather input: a) WM_KEYDOWN, WM_KEYUP for Keyboard messages b) WM_MOUSEMOVE, WM_MOUSELBUTTON... for Mouse Messages c) WM_INPUT for high precision Mouse Messages d) OnUpdate() where XInput and all joysticks get updated I do not want to use Direct Input only, because I still need a way to access XInput. And on the other hand it is possible to enumerate XBOX controller like DirectInputDevice8 object, but you loose force feedback support. I know, that action mapping is supported with directx, but I would like something easier to set up and easier to configure. Is there something like an enumerator list for KEYBOARD_A, KEYBOARD_LEFT, MOUSE_X-, MOUSE_Y-, JOYSTICK_AXIS_UP ? For example a method like this: DWORD WaitForAnyInput() if (any keyboard down) then return KEYBOARD_PageDown for example if (mouse movement) then return MOUSE_LEFT... if (joystick axis up) return Joystick_UP etc... I do not want to reinvent the wheel with all possible enumerators. And then when all set up, how do you apply acttions? Mapping.Add(KEYBOARD_UP, FROWARD_PLAYER1); Mapping.Add(KEYBOARD_DOWN, BACKWARD_PLAYER1); Mapping.Add(JOY_AXIS_UP, FROWARD_PLAYER2); Mapping.Add(JOY_AXIS_DOWN, BACKWARD_PLAYER2); Thankyou in advance!
Endurion
Endurion
I've put my own action mapper on top. I enumerate all objects and put them in a list. I can access the list and don't need to take the input device in account directly.

The list is processed like a giant digital gamepad (i'm converting any analog input to simple digital by using certain offsets/ranges).
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
ApochPiQ
ApochPiQ
The solution I've used is a simple "Input ID" structure:

enum InputSource{  InputSource_Keyboard,  InputSource_MouseButtons,  InputSource_MouseAxes,  InputSource_JoystickButtons,  InputSource_JoystickAxes,};struct InputID{  InputSource Source;  int ID;  // Snip some constructors and operators and such for brevity};// Example usageMapper.AddButtonAction(InputID(InputSource_Keyboard, VK_UP), Action_Forward);Mapper.AddButtonAction(InputID(InputSource_Keyboard, VK_DOWN), Action_Reverse);



The Source member is filled out with a corresponding value from the enum to represent where the ID came from. The ID itself is the original input value - for example, VK_DOWN (or DIK_DOWN if you prefer the DIK_ macros) and so on. This allows me to use the original constants to identify each type of input, without risking collisions between the values - i.e. I don't have to create my own giant enumeration for all possible inputs.

The Mapper class is essentially just a wrapped std::map that translates InputIDs into ActionCodes. The ActionCodes are then dispatched via a callback mechanism to the code modules that handle each action.

(It's a fair bit more complicated than that internally, but that's because the system has to deal with true analog controls, multiple mapping contexts, dynamically cross-mapping digital and analog inputs, single-shot actions vs. repeated action "states", and so on; but the basic idea still holds.)
Samurai Jack
Samurai Jack
Outstanding!

It was exact the solution I was looking for. Thank you very much for your posts. If anyone has further more improovments, please let me know, it would great if I could gather some additional knowledge.

Feel free to post any additional hints or thoughts!
Thank you very much!
123abcd1983
123abcd1983
Quote:
Original post by ApochPiQ
The solution I've used is a simple "Input ID" structure:

*** Source Snippet Removed ***


The Source member is filled out with a corresponding value from the enum to represent where the ID came from. The ID itself is the original input value - for example, VK_DOWN (or DIK_DOWN if you prefer the DIK_ macros) and so on. This allows me to use the original constants to identify each type of input, without risking collisions between the values - i.e. I don't have to create my own giant enumeration for all possible inputs.

The Mapper class is essentially just a wrapped std::map that translates InputIDs into ActionCodes. The ActionCodes are then dispatched via a callback mechanism to the code modules that handle each action.

(It's a fair bit more complicated than that internally, but that's because the system has to deal with true analog controls, multiple mapping contexts, dynamically cross-mapping digital and analog inputs, single-shot actions vs. repeated action "states", and so on; but the basic idea still holds.)


Hi just wondering how you make the "TEXTAREA", i try some code like below in this forum.... but it didn't appear the text area also :(, wish you could tell me how :)


style="scrollbar-base-color:pink;scrollbar-arrow-color:purple;">
Text in the box


iNsAn1tY
iNsAn1tY
Quote:
Original post by 123abcd1983
Quote:
Original post by ApochPiQ
The solution I've used is a simple "Input ID" structure:

*** Source Snippet Removed ***

The Source member is filled out with a corresponding value from the enum to represent where the ID came from. The ID itself is the original input value - for example, VK_DOWN (or DIK_DOWN if you prefer the DIK_ macros) and so on. This allows me to use the original constants to identify each type of input, without risking collisions between the values - i.e. I don't have to create my own giant enumeration for all possible inputs.

The Mapper class is essentially just a wrapped std::map that translates InputIDs into ActionCodes. The ActionCodes are then dispatched via a callback mechanism to the code modules that handle each action.

(It's a fair bit more complicated than that internally, but that's because the system has to deal with true analog controls, multiple mapping contexts, dynamically cross-mapping digital and analog inputs, single-shot actions vs. repeated action "states", and so on; but the basic idea still holds.)

Hi just wondering how you make the "TEXTAREA", i try some code like below in this forum.... but it didn't appear the text area also :(, wish you could tell me how :)


style="scrollbar-base-color:pink;scrollbar-arrow-color:purple;">
Text in the box


GameDev doesn't allow most HTML tags in forum posts (tags like , , and are OK, though). If you want a source box like the one ApochPiQ used, put [source] ... [/source] tags around the text you want contained. Hit the Edit button on ApochPiQ's post above for a look.
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.