Solved

Intercepting WM_KEYDOWN messages

Posted on 1998-08-12
5
489 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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