Archived

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

hello_there

windows keys

Recommended Posts

i''m trying to make a tetris game and my keyboard key checking bit doesn''t work. Can someone please tell me how to do keyboard checks in open GL. Plus i can''t remember how to make things move for example when you press left the block moves left. i''m very new to open GL hmmm interesting

Share this post


Link to post
Share on other sites
Open GL doesn''t have anything for input. Open GL is graphics only. You will either have to settle for normal windows messages or use Direct Input in your program.

NeHe''s tutorial has an interesting way of doing this though by having an array of keys(bool data type). And when a KeyDown message is received it will set the corresponding array element to that key to true. Therefore you know its being held down until its false. And it should change to false when KeyUp is received. Also using that method you can tell if two keys are being pressed(two key flags are set to true).

If I didn''t explain it will enough just look at NeHe''s first tutorial. The one that sets up a window under Windows OS.

"Ogun''s Laughter Is No Joke!!!" - Ogun Kills On The Right, A Nigerian Poem.

Share this post


Link to post
Share on other sites
the only problem with this method is that sometimes if you press too many keys at once, and then let go of some of them in a different order than you pressed them, it gets confused and the "pressed keys" array is not right... for example, if you press "ASDFGHJKL" then let go of "SGH", it might think than all of them are still pressed until you completely let up on all of them... i can''t explain why, but i have noticed this with both my keyboard and a few others i have used.
then again, why would you want to press 9 keys at once in any game?

--- krez (krezisback@aol.com)

Share this post


Link to post
Share on other sites
Actually I have been in the situation where I have needed to detect many, many keys for a music program I was making (the computer keybaord acted as a musical keyboard), I found it to be pretty erratic, as certain key combinations can work ok up to about 5 and some only about 3.

Does anyone here know if there is any benefit to using DirectInput over standard commands like GetKeyState?

Share this post


Link to post
Share on other sites