If you're looking for an example of how to use GetAsyncKeyState:
Code:
#pragma comment( lib, "user32.lib" )
#pragma comment( lib, "gdi32.lib" )
#include <windows.h>
#define VK_A 0x41
#define WINDOW_CLASS_NAME "VIRTUALKEYDEMO"
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
HDC hdc;
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
}
break;
default:
break;
}
return (DefWindowProc(hwnd, msg, wparam, lparam));
}
int WINAPI WinMain( HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASSEX winclass;
HWND hwnd;
MSG msg;
HDC hdc;
winclass.cbSize = sizeof(WNDCLASSEX);
winclass.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if (!RegisterClassEx(&winclass))
return(0);
if (!(hwnd = CreateWindowEx(NULL,
WINDOW_CLASS_NAME,
"Virtual Key Demo for press and release of A key",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0,
400,100,
NULL,
NULL,
hinstance,
NULL)))
return(0);
while(TRUE)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
hdc = GetDC(hwnd);
if(GetAsyncKeyState(VK_A) & 0x8000)
TextOut(hdc, 0,16, "A key: 0", 8);
else
TextOut(hdc, 0,16, "A key: 1", 8);
ReleaseDC(hwnd, hdc);
}
return(msg.wParam);
}