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


New keyboard input problem, HELP!!!

Recommended Posts

JIMbond21    122
I figured out how to use the GetKeyboardState and GetKeyState functions, but when I use this method below to determine if a key is currently pressed it acts like the keys are toggled and makes the object that uses the x and y values keep moving and reverse direction if I hit the different keys. if(GetKeyState(VK_UP)){ y -= 1; } if(GetKeyState(VK_DOWN)){ y += 1; } if(GetKeyState(VK_RIGHT)){ x += 1; } if(GetKeyState(VK_LEFT)){ x -= 1; } On the MSDN website under these functions it talks about the return values and about a high order bit and a low order one that determines whether the key is toggled or pressed, I cant figure out how to determine just if its pressed, without using the message handler, PLZ HELP. THX, JAP

Share this post

Link to post
Share on other sites
JY    289
You need to check the individual bits of the returned SHORT to see the state of the key.

For example, if you just want to know if it''s down - you need to check that the highest bit is set:

if (GetAsyncKeyState(VK_UP) & 0x8000) {

"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan

Share this post

Link to post
Share on other sites