Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Programming Code to intercept keystrokes

Posted on 2004-10-07
Medium Priority
Last Modified: 2008-02-26
I basically want my parent frame to intercept the keystrokes of the "q", "w", "e", "a", "s", "d", "z", "x", "c", "1", "2", "3" keys.  I tried to make an accelerator table for the Child MDI Frames, but they only respond when active to the keys I have assigned to them.  I have 2 frames that each need to, no matter what, intercept those keystrokes when the program is maximized and the parent frame has focus.

How do I do this?  Or is there a way to have the accelerator table switch frame focus on keypress...I just need it to work...and fast!

I'm designing in Visual C++ 6.0 and am using the wxWidgets libraries, currently, if that helps.

Question by:vivekpara
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
  • 3
LVL 86

Expert Comment

ID: 12252586
The easiest way probably is using a 'local' (i.e. non-system-wide) hook that filters for these keys and takes the appropriate action. See ("Win32 Hooks")
LVL 86

Accepted Solution

jkr earned 2000 total points
ID: 12252701
BTW, a little example:

HHOOK       g_hhk   =   NULL;

LRESULT CALLBACK KbdProc    (   int     nCode,  // hook code
                                WPARAM  wParam, // virtual-key code
                                LPARAM  lParam  // keystroke-message information


    /* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
    /* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */

    switch ( wParam)

        case 'q: //...

    return  (   CallNextHookEx  (   g_hhk,

void SetHook ()

    g_hhk   =   SetWindowsHookEx    (   WH_KEYBOARD,
                                        ( HOOKPROC) KbdProc,
                                        GetCurrentThread ()


Author Comment

ID: 12252781
Forgive my stupidity, but where would the Function go in the case Function?  Does the case statement just need brackets for each function that it would call?  Or is it more like an ENUM Table and needs to be linked?

LVL 86

Expert Comment

ID: 12253297
>>where would the Function go in the case Function?

You'd add the functionality for handling each of the keys you're interested in in each of the 'case' branches, like

    switch ( wParam)

       case 'q': //...

        HandleThatKey_q_wasPressed ();


       case 'e': //...

        HandleThatKey_e_wasPressed ();



Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

660 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