user defined keys

BlitzMax Forums/BlitzMax Beginners Area/user defined keys

jkrankie(Posted 2005) [#1]
I'm adding to my game the ability for users to define their own keys, but have hit a bit of a brick wall. I can't work out how to do it at all. This is what i've done so far in a little test program.

(code)
Graphics 640,480,0,60
Local upkey%

While Not KeyHit(key_escape)

upkey=GetChar()

If KeyDown(upkey) Then DrawText "up",10,10

Flip
Cls
Wend
(/code)

The above doesn't work, and im a bit stumped as to what to try next

any suggestions/code examples?

cheers
Charlie


tonyg(Posted 2005) [#2]
You could use upkey=waitkey() which will wait until the user hits a key and return the integer value.
Getchar returns the ascii code and doesn't sem to be mapped for the cursor keys.


jkrankie(Posted 2005) [#3]
thanks very much, i hadnt thought of looking for waitkey

cheers
charlie


Rimmsy(Posted 2005) [#4]
Edit: Wait, think I got the wrong end of the stick. Sorry.

if you have a look at the help for keydown and keyhit, there are specific key codes for each key. the up key is KEY_UP, so
 If KeyDown(KEY_UP) Then DrawText "up",10,10

will work. To assign user specified keys you can use an array like:
local playerOneKeys[]=[KEY_UP,KEY_DOWN,KEY_LEFT,KEY_RIGHT,KEY_ENTER]

if keydown(playerOneKeys[0])
debuglog "player has pressed their up key."
endif

Then you can change it easily by going:
playerOneKeys[4]=KEY_F

which will change the player's first key from ENTER to F

That what you were thinking of?


jkrankie(Posted 2005) [#5]
yes, but its just a different way of doing the same thing.

thanks a lot
charlie


Perturbatio(Posted 2005) [#6]