Key states in API?
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
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:
Alternatively, you can use the GetAsyncKeyState function to find out if a key is pushed immediately.
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
Popular Topics
Advertisement