Fast and Good Keyboard/Mouse Test without the message handler | ||||||||||||||||||||||
| ||||||||||||||||||||||
SHORT GetAsyncKeyState( int vKey // virtual-key code ); vKey is the virtual key code of the keyboard or mouse button you want to test. GetAsyncKeyState(..) returns true if this button is pressed and false if not. I always use GetAsyncKeyState(..) for my games and demos because it can be used simply like this without a long message handle. Here is a little example how to use it: void CheckKeyboard() { //Escape is down if (GetAsyncKeyState(VK_ESCAPE)) { PostMessage(hWnd,WM_CLOSE,0,0); } //Right mouse is down if (GetAsyncKeyState(VK_RBUTTON)) { //.. //Do something //.. } } In this function, we will check what keys are down. You could now use this function in your main loop or somewhere else in your code. Here is a list of the most important virtual key codes:
Tags: C++ GetAsyncKeyState PostMessage VK_DOWN VK_ESCAPE VK_LEFT VK_RBUTTON VK_RIGHT VK_SHIFT VK_SPACE VK_UP | ||||||||||||||||||||||
| ||||||||||||||||||||||
| ||||||||||||||||||||||
Login for comment |