Jump to content
  • Advertisement


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


New keyboard input problem, HELP!!!

This topic is 5456 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!