Jump to content
  • Advertisement
Sign in to follow this  
Trillian

[Win32] GetKeyboardState and VK_ESCAPE

This topic is 4202 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

Hello I'm done with the input part of my engine so I'm happy. Now I come to test it and the first thing I see is my window disappearing for no reason! Tracing down, I found that the problem was actually with "GetKeyboardState". This function returns the state of keyboard buttons but something weird happens. When my program boots and calls this function, windows says that the VK_ESCAPE key is down already! As a result, my program closes immediately. I know Win32 functions such as GetKeyboardState are not super well suited for games but why is it giving me wrong information, did anyone else had such problems with GetKeyboardState?

Share this post


Link to post
Share on other sites
Advertisement
Perhaps you are not reading it correctly...

When you use that function only one bit of the returning value tells you whether the key is up or down, the rest tell other information. In the "Game Programming Genesis" article by Joseph Farrell http://www.gamedev.net/reference/programming/features/gpgenesis3/page8.asp
there's a really useful macro for doing this...

#define KEYSTATE(vk) ((GetAsyncKeyState(vk) & 0x8000) ? TRUE : FALSE)


EDIT: Sorry, I didn't read the function well. You are using GetKeyboardState...

[Edited by - jorelmb on March 24, 2007 11:02:26 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

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