Solved

Detecting F10 with WM_KEYDOWN

Posted on 1998-11-12
5
637 Views
Last Modified: 2013-12-03
I need to detect the keypress of every single function key, and I'm having trouble with F10 because Windows automatically intercepts the F10 message to activate the menu (like an ALT press). How can I get around this?
0
Comment
Question by:HoJu
  • 3
5 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
You could use an application-local message hook, e.g.

// this is a WH_GETMESSAGE hook
LRESULT CALLBACK HookProc   (   int     nCode,  // hook code
                                WPARAM  wParam, // removal flag
                                LPARAM  lParam  // address of structure with message
                            )
{
    PMSG    pmsg    =   ( PMSG) lParam;

    if  (   0   >   nCode   ||  PM_NOREMOVE ==  wParam)
        {
            return  (   CallNextHookEx  (   g_hhk,
                                            nCode,
                                            wParam,
                                            lParam
                                        )
                    );
        }

    if  (   WM_KEYDOWN  ==  pmsg->message  
        )
        {
            /* this one is for us, so check key state */
            if  (       0x80000000 & GetKeyState    (   VK_F10)
                )
                {
                    // signal it to application
                }
        }

// ...

}

0
 

Author Comment

by:HoJu
Comment Utility
Hmm. That doesn't seem to work -- I wrote a hook function, and it can catch pretty much every keystroke _except_ for F10.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Hmm - that's strange... i thought Windows would filter 'F10' in 'TranslateMessage()' for 'WM_KEYDOWN'. But what about 'WM_SYSKEYDOWN'?
0
 
LVL 2

Accepted Solution

by:
abesoft earned 50 total points
Comment Utility
From the docs:
The WM_SYSKEYDOWN message is posted to the window with the keyboard focus when the user presses the F10 key (which activates the menu bar) or holds down the ALT key and then presses another key.

(This is what jkr had commented on, I think...)
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
abesoft - yes, that's exactly what i meant ...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

771 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

7 Experts available now in Live!

Get 1:1 Help Now