Solved

Intercepting WM_KEYDOWN messages

Posted on 1998-08-12
5
488 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 98
Get filename and folder into excel 7 84
centeredAverage challenge 8 186
Sed question 2 124
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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…
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.

730 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