QuestionHelplow level keyboard hook

Posts 1–5 of 5 · Page 1 of 1
low level keyboard hook
Im making a simple logger that logs the amount of key pressed, and the amount of mouse clicks.
I got my hook working, and all the keys are being logged, but i dont know how to log the mouse clicks:S

I tried the following:

Code:
LRESULT CALLBACK keyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam){
    PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) lParam; 
    if (nCode==HC_ACTION){
        if (wParam == WM_KEYDOWN){
            
            switch (p->vkCode)
            {
            case VK_LBUTTON:        cout << l++ << endl; break;
            case VK_MBUTTON:        cout << m++ << endl; break;
            case VK_RBUTTON:        cout << r++ << endl; break;

            default:               cout << keystroke++ << endl;;
            }
        }
    }
    return CallNextHookEx(NULL, nCode, wParam, lParam);
}
The keystroke counts up just fine.
Is a mouse a keyboard? No. Use a low level mouse hook.
Quote Originally Posted by Jason View Post
Is a mouse a keyboard? No. Use a low level mouse hook.
ofc -_- so stupid of me.

Got it working now
Code:
LRESULT CALLBACK mouseHookProc(int nCode, WPARAM wParam, LPARAM lParam){
    PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT) lParam;
    if (nCode==HC_ACTION){

        switch (wParam){
            case WM_LBUTTONDOWN: l++ << endl; break;
            case WM_RBUTTONDOWN: r++ << endl; break;
        }
    }
    return CallNextHookEx(NULL, nCode, wParam, lParam);
}
Code:
HHOOK mouseHook = SetWindowsHookEx(WH_MOUSE_LL,
(HOOKPROC)mouseHookProc,
hInstance,
0);
One more question. This hook doesnt work when im playing a game, is this because the game uses the same kind of hook?
Is there an easy way to check if buttons are pressed in any game? (not just one specific game)
Quote Originally Posted by AlphaDog209 View Post
One more question. This hook doesnt work when im playing a game, is this because the game uses the same kind of hook?
Is there an easy way to check if buttons are pressed in any game? (not just one specific game)
SetWindowsHook relies on the program using the Windows Messaging Queue to handle input. If the application is something like a DirectX game, it may use an alternate method of trapping input, such as DirectInput. In such a case, a hook set by SetWindowsHook won't know anything happened.
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?