键盘HOOK显示按键信息
GetKeyNameText(MapVirtualKey(iKeyValue,0)<<16));
//iKeyValue 的值为 VK_ESCAPE 等
LRESULT CALLBACK LowLevelKeyboardProc (INT nCode, WPARAM wParam, LPARAM lParam)
{
// By returning a non-zero value from the hook procedure, the
// message does not get passed to the target window
KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *)lParam;
BOOL bControlKeyDown = 0;
HWND hWnd = GetForegroundWindow();
WCHAR szClassName[MAX_PATH] = {0};
::GetClassName(hWnd, szClassName, MAX_PATH);
KBDLLHOOKSTRUCT *kb =(KBDLLHOOKSTRUCT *)lParam;
if (wParam == WM_KEYDOWN)
{
wchar_t szKeyName[100];
DWORD t = (kb->scanCode<<16) + (kb->flags<<24);
::GetKeyNameText(t,LPWSTR(szKeyName),100);
::SetDlgItemText(hWnd,IDC_KeyInput,LPCWSTR(szKeyName));
return true;
}
return CallNextHookEx(Hook,nCode,wParam,lParam); //将消息还给钩子链,不要影响别人
}