Solved

Intercepting WM_KEYDOWN messages

Posted on 1998-08-12
5
480 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 83
NotAlone Challenge 20 72
Annoying "thing" blocks my view 4 51
Problem to open Excel file 15 43
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

22 Experts available now in Live!

Get 1:1 Help Now