您的位置:首页 > 其它

记录键盘按键

2014-11-28 18:53 148 查看
#include <iostream>
#include <windows.h>
#include <winuser.h>
using namespace std;
LRESULT CALLBACK  LowLevelKeyboardProc(int nCode,WPARAM wParam,LPARAM lParam)
{
KBDLLHOOKSTRUCT *pKeyBoard = (KBDLLHOOKSTRUCT *)lParam;
switch(wParam)
{
case WM_KEYUP://when the key has been pressed and released
{
switch(pKeyBoard->vkCode)//Check to see what key has been pushed
{
case VK_RETURN:// The return/enter key has been pushed
DWORD timestamp = pKeyBoard->time;
cout<<timestamp<<endl;// This shows our timestamp when the key was pushed
break;
}
}
default:
return CallNextHookEx(NULL,nCode,wParam,lParam);
}
return 0;
}
int main()
{
// Retrieve the applications instance
HINSTANCE appInstance = GetModuleHandle(NULL);
//Set a global Windows Hook to capture keystrokes
SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,appInstance,0);
MSG msg;
while(GetMessage(&msg,NULL,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: