Advertisement Jump to content


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


Key states in API?

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

Can someone tell me how to detect and use key states/messages in API? I know you can use the message switch for WM_KEYUP and KEYDOWN etc...but Im not so sure how can some1 please give a simple example? im trying to get started in games and am first trying to get a square to move up when i press up and down when i press down. If any1 has the time example code would be awesome. Thanks

Share this post

Link to post
Share on other sites
WM_KEYDOWN notification

In your window message handler, just handle WM_KEYDOWN. The WPARAM is the virtual key code of the key that is being pushed. Here is the list of virtual key codes.

So to do something like move squares you could do something like this:

// in your window handler
case VK_UP:
// move square up
case VK_DOWN:
// move square down


Alternatively, you can use the GetAsyncKeyState function to find out if a key is pushed immediately.

Share this post

Link to post
Share on other sites
Just a little note, there are no virtual key codes for the characters that you can type. For example, there''s no such thing as VK_A, instead you would just use ''A''.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!