Link to home
Start Free TrialLog in
Avatar of davidmurphy
davidmurphy

asked on

Intercepting WM_KEYDOWN messages

How do I intercept all WM_KEYDOWN messages regardless of which window they routed to ?
Basically I am trying to write an app which will run in the background and monitor all keystrokes and pop up a dialog when it receives a particular keystroke combination.
Avatar of amby
amby

You can change the window proc of each window you want to "trace", the instruction is SetWindowLong...

CMyWnd::OnWhatYouWant()
{
    //----- do it in every window you want to trace...
    OldWndProc = SetWindowLong(m_hWnd, GWL_WNDPROC, NewWndProc)
}

UINT NewWndProc (HWND, MESSAGE, LPARAM, WPARAM)
{
    //---- HWND identifies the window !!!

    //---- refer to online doc for exact syntax
    switch (MESSAGE) {
    case WM_KEYDOWN:
        ExecMyCode();
        break;
    }

    //---- It is often interesting...
    return CallWindowProc(OldWndProc,...);
}

Good luck
Avatar of davidmurphy

ASKER

Thank you for your answer but I dont think that it is quite what I am looking for.
Isn't there a way of hooking into the windows message queue in the same way (I imagine) that 'Spy' works ?

Thanks
I imagine Spy is modifying the window proc...

(in fac you can "empile" the window procs, very usefull !!)
You want to look at HOOKs.
ASKER CERTIFIED SOLUTION
Avatar of arun_ta
arun_ta

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial