Jump to content
  • Advertisement


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


bind DIKEYS "Quake Style"

This topic is 6965 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone know of a simple/fast way of being able to bind a command to a key using Direct Input? I already have a simple scripting language(if that''s what you want to call it) already implemented. The reason that I ask is because I thought parsing strings in a fps in realtime would be a bad idea. If you can think of a better idea, then i''d like to read about it.

Share this post

Link to post
Share on other sites

You can do the parsing on startup, or when the user binds a new command. There is no need to continously parse strings in real time.

The simplest way to have commands bound to keys would be a keep an array of functions pointers which are intialized to null. When a function is bound, simply parse the string entered to see if its a bindable command, and parse the key entered to see if its a valid key. Then in your input event handler function, check to see if you have a nonzero pointer for the key pressed in the array and call it.

Here''s some psuedocode. I''m just typing it up so don''t take to a compiler =)

typedef void (*PCOMMAND)();

void MoveForward()
{ ........ }

void BindCommand(const char * string)
int key;
char * command;

//parse string for command and key here

if(key < 0 // key > TOTAL_KEYS)
error bad key index, return

if command == "+forward"
fnCommands[key] = &MoveForward;

void HandleKeyEvent(const KeyEvent &key)
if(key.state == BUTTONDOWN)

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!