KeyDown和KeyUp事件

时间:2014-12-03 11:57:53

标签: c++ winapi console

我一直在使用GetASyncKeyState& !GetASyncKeyState但它没有很好的响应,因为我想要跟踪的密钥在释放之前被暂停了一段时间。

我需要能够按住Mouse1按钮,然后在按钮释放时触发事件。

1 个答案:

答案 0 :(得分:1)

解决了它,谢谢你试图提供帮助。

LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{

PKBDLLHOOKSTRUCT k = (PKBDLLHOOKSTRUCT)(lParam);
POINT p;

if (wParam == WM_LBUTTONUP)
{
    _bAimed = false;
}
return CallNextHookEx(0, nCode, wParam, lParam);
}

//...

MouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, hInstance, 0);

//...

while (1)
{
MSG msg;
    if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}