键盘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);  //将消息还给钩子链,不要影响别人

 


}

posted @ 2014-04-18 13:13  FREE小宝  阅读(435)  评论(0编辑  收藏  举报