View Full Version : User-Customized Keyboard/Mouse keys

11-08-2007, 03:58 AM
Well, my problem is that I've been trying to decide how I might make a user be able to customize what keys do what in a game. I'm not 100% sure how, but I'm also not asking for specific code for libraries. All I want is maybe some pseudo code which would be adaptable to most situations. Or, if this is too difficult, I will be using the Pheonix Engine, in Free Pascal, with no extra IDE's (just plain old pure FPC).

Can anyone help?


11-08-2007, 08:09 AM
Hi DarknessX,
I had to implement this sort of system for Hero X. Basically what you need to do is make you input logic work independent of Key and use a system based on actions.

So code wise instead of testing for a key press you test for an action.

It was a while ago, so if I remember correctly it went something like this.

TGameAction = ( gaMoveLeft, gaMoveRight, gaMoveForward......... );
TGameActions = set of TGameAction; // for multipleActions at the same time

GameActions : TGameActions;

if gaMoveLeft in GameActions then
// Move the character left

if gaMoveRight in GameActions then
// Move the character right


Now the mapping part involves having an inmemory table that you can look up to see if a KeyPress/MousePress maps to an action. In HeroX we persistented this info between games by saving it out to an INI file. which looked something like this...


I hope this gets you started.

11-08-2007, 08:16 AM
Hmmm, That does. Thanks, savage. That is really quite interesting... I was thinking along similar lines, but wasn't quite sure if it was the correct/fastest/proper way to go about it.