how to keep my hook on top of the hook chain

Viewed 130

I am working on a school project in which I am writing an application. I'm registering a global hook in windows, I would like to perform changes on events reaching an application.

So currently, I have a global hook installed, but somehow the events are probably reaching the application first, (based on the synthoms I see), and only afterwards my hook.

I am curious, how do I keep my hook on top of the hook chain? Also, application specific hooks get called first in front of the global hooks?

Edit, adding code (this is how it looks like currently, this obviously doesn't try to re-register the hooks in order to keep it on the top. I had another version where it was re-registering it in a while loop with a sleep, but that didn't work.):

int main()
{


HHOOK hhkLowLevelKybd;

    try
    {
        hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyBoardProc, 0, 0);

        MSG msg;
        while (!GetMessage(&msg, NULL, NULL, NULL))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        cout << "Hook installed" << endl;
    }
    catch (...)
    {
        cout << "Exception occured. Stopping, uninstalling hook." << endl;
    }

    UnhookWindowsHookEx(hhkLowLevelKybd);

    return(0);
}
0 Answers
Related