Solved

Programming Code to intercept keystrokes

Posted on 2004-10-07
4
293 Views
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.

Thanks!
0
Comment
Question by:vivekpara
[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
  • 3
4 Comments
 
LVL 86

Expert Comment

by:jkr
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_hooks32.asp ("Win32 Hooks")
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 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,
                                    nCode,
                                    wParam,
                                    lParam
                                )
            );
}

void SetHook ()
{

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

}
0
 
LVL 2

Author Comment

by:vivekpara
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?

Thanks.
0
 
LVL 86

Expert Comment

by:jkr
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 ();

        break;

       case 'e': //...

        HandleThatKey_e_wasPressed ();

        break;
   }

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

636 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