Jump to content
  • Advertisement

Archived

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

RedRabbit

Key states in API?

This topic is 5275 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
Advertisement
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 WM_KEYDOWN:
switch(wParam)
{
case VK_UP:
// move square up
break;
case VK_DOWN:
// move square down
break;

}
break;


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