New keyboard input problem, HELP!!!

Started by
1 comment, last by JIMbond21 20 years, 8 months ago
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
THX,JAP
Advertisement
To see if a key is down:

if (GetKeyState(VK_LEFT) & 0x80)
//VK_LEFT is pressed


Qui fut tout, et qui ne fut rien
Invader''s Realm
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
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan

This topic is closed to new replies.

Advertisement