Archived

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

Woody FX

Can you detect if the key has been held down

Recommended Posts

Woody FX    169
I''ve almost completed my first game and its pretty ok except for the controls whic require the user to tap the key to move the object about the screen. IS the away to detect that the key is being held down and just keep the object moving across the screen all the while?? Thanks guys

Share this post


Link to post
Share on other sites
gonen    122
directinput lets you get the state of all keys.
the state is pressed/unpressed so if you see the key still pressed , keep the object moving

Share this post


Link to post
Share on other sites
CodeMunkie    805
I doubt he is using DirectInput on a PDA. All you do is keep a flag called keydown (one for each key you need to track). When the user hits the key you set keydown to true. When the user releases the key you set keydown to false. In your update loop you check the value of keydown.



All you will ever need to know.

Share this post


Link to post
Share on other sites
Thunder_Hawk    314
This is only possible if you can tell when a key is released.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

Share this post


Link to post
Share on other sites
Vex    122
You don't say what device you're using.

But if you're talking about a MIDP application, then there are keyPressed , keyReleased and keyRepeated methods that you can use.

Vex / G4MES.net Developer



[edited by - Vex on August 14, 2003 9:07:45 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Woody:
In most mobile devices you have got two events

a) keydown/pressed

b) keyup/released

all you do is keep a table of boolean values which indicate using true/false statements if a key is hold down or not atm.

each time you get a keydown event with key value you save in this table cell 1 (like keys[keynr]=1
each time you get a keyup event you save 0 in this table

Now to learn if key x is holded down you just check if (keys[x]==1)

Simple and effective solution :-)

Share this post


Link to post
Share on other sites