Archived

This topic is now archived and is closed to further replies.

GroZZleR

Input Engine - Problems with mapping keys.

Recommended Posts

Hey all, I''ve come here looking for some theoretical design input (couldn''t resist the pun) on my engine''s input engine. In smaller projects, I believe people define a set amount of actions (ie, MOVE_UP, MOVE_LEFT) and than map those keys to those actions. I''m doing sort of the opposite, where you have a static list of keys and map actions to the keys instead. This allows you to add 100s or even 1000s of actions and limits you only to the number of keys on your keyboard. The problem, I''m having, is of course doing the actual mapping! I just finished the console part of the program, so I can handily type something like "bind x +shoot" and when you push the x button, you go on your marry little way shooting. The problem is, translating the ''x'' to something like DIK_X to use with the actual input engine. Once I get over this hurdle, its clear sailing. Also going to need bindings for things like MB_LEFT and MB_RIGHT and all sorts of those fun actions. Right now, I''ve got the actual parsing done and the mapping of actions to buttons (ie, x = +shoot in our little example) but am stuck on how to translate X to DIK_X or any other ''macro''. Any ideas?

Share this post


Link to post
Share on other sites
Probably a lookup table.


struct KeyEquiv
{
std::string Name;
unsigned char KeyCode;
};


//somewhere...

struct KeyEquiv KeyDefinitions[] =
{
{ "x", DIK_X },
{ "y", DIK_Y },
//etc.

};


Obviously the array is going to be a real bitch to write, but you''re going to probably have to bite the bullet and do it.

Share this post


Link to post
Share on other sites
Actually, yeah, go with Unsuspected's idea.

I forgot about actually having to search through the array std::map will serve you quite nicely.


//you'll definitely want to typedef this

typedef KeyMapType std::map<std::string, unsigned char, less<unsigned char>>;

KeyMap KeyMap;

//add entries like this:

KeyMap.insert( KeyMapType::value_type( "x", DIK_X ) );


[edited by - Promit on March 17, 2004 7:11:25 PM]

Share this post


Link to post
Share on other sites
Oh sweet idea, than I can just add the action right to the map and poof, all in one convenience.

Thanks guys, helpful as always.

Share this post


Link to post
Share on other sites