Solved

Intercepting WM_KEYDOWN messages

Posted on 1998-08-12
5
483 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:davidmurphy
5 Comments
 
LVL 1

Expert Comment

by:amby
ID: 1320637
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
0
 

Author Comment

by:davidmurphy
ID: 1320638
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
0
 
LVL 1

Expert Comment

by:amby
ID: 1320639
I imagine Spy is modifying the window proc...

(in fac you can "empile" the window procs, very usefull !!)
0
 
LVL 3

Expert Comment

by:danny_pav
ID: 1320640
You want to look at HOOKs.
0
 
LVL 1

Accepted Solution

by:
arun_ta earned 100 total points
ID: 1320641
u might like to use Windows Message Hooks (Spy does that...) - except for a DOS window. Enough documentation is there in help files.

Another advanced method is to write a simple driver which intercepts the calls to windows kbd driver. (Visit sysinternals.com for an example)


0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeateFront java challenge 31 92
C++ BOOL WINAPI ReadFile fails on windows 10 when reading from USB cable 9 379
sum28 challenge 31 106
no14 challenge 14 62
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now