Connecting Tech Pros Worldwide Forums | Help | Site Map

Key function changing?

Newbie
 
Join Date: Jul 2007
Posts: 2
#1: Jul 1 '07
I play an internet game, ( It runs on java ).
Im used to using the WASD as my movement keys, Now in this game you use the <^> (arrow) keys to move the camera, Im wondering how would I go about making the WASD keys act like the arrow keys, I would also like to make the Q and E keys act like ESC and F4 respectively. I asked about how I would do this on another forum and heard some people talking about VB, so I went and downloaded VB6. Any ideas, thanks.

Newbie
 
Join Date: Jul 2007
Posts: 2
#2: Jul 6 '07

re: Key function changing?


Come on, one of you must know how to do it. :-(
Robbie's Avatar
Familiar Sight
 
Join Date: Mar 2007
Location: igirisu~
Posts: 184
#3: Jul 7 '07

re: Key function changing?


If you are making this game in VB6, you can (and it probably would be easiest if everyone always did) have what key controls an action stored in a variable.
Uh... that wasn't very clear. >_< Let me try again.

Say you have a control to move left, another to move right, and one to fire.
You know that every key on the keyboard has a keycode?
Well, you can have 3 variables, one for each action (move left/right, fire) - and set each of them to the keycode of the key which you want to use for that action. E.g.

ControlMoveLeft = vbKeyLeft
ControlMoveRight = vbKeyRight
ControlFire = vbKeySpace

Then, I presume you will have a main sub where all your control-handling will be done.
Where you would normally simply do
"If the current key's vbKeyLeft, move to the left..."
you do instead
"If the current key's 'whatever ControlMoveLeft is', move to the left..."

Then you can simply change one of those variables to change the control for that action, at runtime, i.e. without needing to change the game's code and re-compile.

(Actually, it may be better to store all the controls in one array - you'd just need to remember what index of the array represents what control...)

But, I don't know how to simply check if a certain key is being pressed - I only know how to look at the last one which was pressed down.
And that's one of the main reasons why I've never made a game in VB6. :P
Reply