Search results for 'VK_ESCAPE'. 1 post(s) found.
2007/08/27 15:01
Fast and Good Keyboard/Mouse Test without the message handler
2007/08/27 15:01 in C, C++

In this short snippet, I will show you a Win32 function that checks whether a button is pressed or not. The good thing is that you don't need to handle the WM_KEYDOWN message. The second advantage is that it is really easy to use and that it can be used everywhere in the code. Here is the function-definition:
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
//..
}
}
{
//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:
| Virtual Key Code | Corresponding key on the keyboard |
| VK_ESCAPE | Escape |
| VK_SPACE | Space |
| VK_LEFT | Left Arrow |
| VK_RIGHT | Right Arrow |
| VK_UP | Up Arrow |
| VK_DOWN | Down Arrow |
| VK_SHIFT | Shift |
| VK_CONTROL | Control |
| VK_LBUTTON | Left Mouse Button |
| VK_RBUTTON | Right Mouse Button |
Another posts included in "C, C++"
| Using the shell to receive notification of removable media being insert... (0) | 2007/08/28 |
| UDP Send and Receive Using CAsyncSocket (0) | 2007/08/28 |
| Creating and Using a CAsyncSocket Object to use CAsyncSocket (0) | 2007/08/28 |
| Simple CGI Programming in C (0) | 2007/08/27 |
| C++ CGI Example working on Apache (0) | 2007/08/27 |
Trackback : Cannot send a trackbact to this post.
-
Subject different money making ideas
2010/01/28 23:12
moneyideas
-
Subject different money making ideas
2010/01/29 07:33
moneyideas
-
Subject different money making ideas
2010/01/31 16:44
moneyideas
Prev

Rss Feed