Game Development Community

Remapping w,a,s,d to Arrow keys

by Steve · in Torque Game Engine · 10/19/2007 (2:37 pm) · 4 replies

Hi, i successfully (only after reading some valuable posts here) remapped my movement keys from W -- forward, S -- backwards , etc to YGHB as a test. However, what i really want to do is to remap to the following:

Forward -- up arrow
Backward -- down arrow
Left -- left arrow
Right -- right arrow

I do not know how to represent these key presses in the .cs files that I need to update.

Apparently, the arrow keys have no ascii codes (that I could find) nor do i know If the .cs files would accept an ascii code.

If i *did* find an Ascii code, I do not know what, if any, delimiter i would have to put around the code so the script would understand it.

I did find "virtual key codes" representing the arrow keys (37,38,39,40) but when I entered those in, it didn't work. I also tried to do something like this:

"", moveleft
", moveright
etc.

(above syntax not exact, but I think it makes the point)

And that did not work either.

Any help would be greatly appreciated!

#1
10/19/2007 (2:47 pm)
An easy way to find this was to use the starter.fps example and just remap the keys and look in the config.cs in the client folder and the new code was added at the bottom so you can use the arrow keys along with the w,s,a,d,

Up, down, left, right

moveMap.bind(keyboard, "up", moveforward);
moveMap.bind(keyboard, "down", movebackward);
moveMap.bind(keyboard, "left", moveleft);
moveMap.bind(keyboard, "right", moveright);
#2
10/19/2007 (3:16 pm)
Very Impressive! Part of my problem was that it took me awhile to realize that config.cs was the correct file to edit. However, I don't think I ever would have realized to do what you suggested above. Thanks so much.
#3
10/23/2007 (3:30 pm)
I believe these should be changed in default.bind.cs file instead.
config.cs is written from the game when the controls are changed in the options menu system.

My procedure is to change default.bind.cs (or wherever your specific action map is defined) then run the DeletePrefs.bat batch file to delete all the per run saved preference files to make sure that my new settings will "take".

Another possible issue: There may a problem with having multiple binds to the same command function. For example:
moveMap.bind(keyboard, "up", moveforward);
moveMap.bind(keyboard, "w", moveforward);

If you need this, it might be safer to do:
moveMap.bind(keyboard, "up", moveforward2);
moveMap.bind(keyboard, "w", moveforward);

where moveforward2 is a clone of the moveForward function.

Trying to get multiple overlapping comamnds properly tied into the options system is left to the student. (That means: I don't recall solving that one ;) )
#4
10/31/2007 (8:10 am)
Well, I did some testing. If you make the changes in default.bind.cs it works fine.
If you make the changes in config.cs it works fine.
If you make the changes to both files, it works fine.

Config.cs will allow you to have multiple binds to the same command function, at least up to 2. I did not test 3, nor did I test this in default.bind.cs

I am not sure what hidden dangers I might run into by changing this in config.sys, but at this point I am more interested in learning how to do things, than making changes that will be written in stone.

Thanks, Matthew and James for your informative posts. The information may seem trivial to you guys, but to me it is huge!