Key states in API?

Started by
1 comment, last by RedRabbit 19 years, 10 months ago
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
//-----------------------------------------One short sleepe past, wee wake eternally, And Death shall be no more, Death thou shalt die.
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 handlercase 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.
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''.

This topic is closed to new replies.

Advertisement