我希望挂钩键盘,但如果我挂钩,
当我按下并按住它时,
它一直打电话直到我发布它
但我只想像键盘一样打电话
我该怎么办?
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (wParam == WM_KEYDOWN)
{
PKBDLLHOOKSTRUCT pKey = (PKBDLLHOOKSTRUCT)lParam;
int key = pKey->vkCode;
cout << key << endl;
}
if (wParam == WM_KEYUP)
{
PKBDLLHOOKSTRUCT pKey = (PKBDLLHOOKSTRUCT)lParam;
int key = pKey->vkCode;
cout << key << endl;
}
CallNextHookEx(hKBHook, nCode, wParam, lParam);
return 0;
}
int _tmain() {
HMODULE hInstance = GetModuleHandle(NULL);
hKBHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardProc, hInstance, NULL);
MSG Msg;
while (GetMessage(&Msg, NULL, 0, 0)) { DispatchMessage(&Msg); }
return 0;
}