Help with WM_KEYDOWN, SC_KEYMENU & F10 key press

Started by
4 comments, last by mmakrzem 16 years, 5 months ago
I'm using the WM_KEYDOWN message send to WinProc to do some work in my program, but I have noticed that when I press F10, focus is lost to my window. My program never gets a WM_KEYDOWN message. Instead it gives me a WM_SYSCOMMAND with wParam = SC_KEYMENU. Is there anyway to disable this behaviour so that when I press F10, I instead get a WM_KEYDOWN message with VK_F10 being passed in as the wParam? I also get strange behaviour when I press F12 on the keyboard. .... basically my program crashes.... not sure why yet. All other F keys work fine. Another thing; anyone know why I'm getting wParam = VK_RETURN when I press the enter key on the number pad? I was thinking I should get VK_SEPARATOR. The "Print Screen" button doesn't seem to work either .... I tried VK_SNAPSHOT and VK_PRINT but neither work. Oh, and what is the deal with the left/right shift, ctrl and alt buttons. When I press them, I can't seem to differentiate between the left ones and the right ones.
Advertisement
F10 is the shortcut key to enter a windows' menu. It should be enough to not pass a valid HMENU handle. I haven't tested this though. You probably want to avoid using F10 if it doesn't work though.
If you insist, you can get F10 by catching WM_SYSKEYDOWN and NOT passing the message on to DefWindowProc.

F12 is causing a manual breakpoint since Windows 2000 and up (NT?). It's annoying since you cannot use F12 for anything useful while debugging. It's supposed to help you so you can enter debug mode at any time. It's not a bug in your code.

For separating left/right control, alt and shift: There's bit 24 in LPARAM, it's set to 1 if the right key was used.

Isn't VK_SEPARATOR the komma/dot key in the numpad?

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Ahh, okay I see now that F12 is fine. When I run the code without the debugger everything is okay.

My program doesn't have a menu, but it is still giving me SC_KEYMENU when F10 is pressed.

Thanks for the tip on left/right keys. I'll think this will fix my problem.

What is the Virtual Key Code to the enter key on the numberpad then?

Still don't know what to do about F10. I tried running my program in full screen mode, with no menu/window but when I press F10 I still get SC_KEYMENU.
It's actually very simple.

To begin with, you game should treat WM_KEYDOWN and WM_SYSKEYDOWN as the same message, they are, but sent as diffrent messages.

Then in your Wnd procedure do the following:
case WM_SYSCOMMAND:    {        switch( wParam & 0xFFF0 )        {        case SC_KEYMENU:        // Process, but do nothing             return 0;           // (prevents Windows notification ding!)        }    }    break;


A made a post about this a while back:
http://www.gamedev.net/community/forums/topic.asp?topic_id=470716

Make sure you "return 0;" in your wnd proc to process the WM_KEY* messages.

Best regards,
John
Quote:
For separating left/right control, alt and shift: There's bit 24 in LPARAM, it's set to 1 if the right key was used.


I looked into this but lParam is only good for alt and Ctrl keys. It doesn't work to separate the left & right shift keys.

I was recommended to try:
Quote:
// Compliments of Game Coding Complete(thx Mike McShaffry!)
case WM_KEYDOWN:
{
UINT oemCode = int(lParam & (0xff << 16)) >> 16;
if (wParam == VK_SHIFT && oemCode == 0x2A)
{
// Left shift control.
}
else if (wParam == VK_SHIFT && oemCode == 0x36)
{
// Right shift control.
}
}break;


but this doesn't work either. If I press and hold both shift keys down and then release both, one of them still remains active.
here are some test results:

Quote:
Left Shift Key Down 10 2a0001
Left Shift Key Up 10 c02a0001
Right Shift Key Down a1 360001
Right Shift Key Up a1 c0360001

Left Shift Key Down 10 2a0001
Left Shift Key Down 10 402a0001
Left Shift Key Down 10 402a0001
Left Shift Key Down 10 402a0001
Right Shift Key Down a1 40360001
Right Shift Key Down a1 40360001
Right Shift Key Down a1 40360001
Right Shift Key Down a1 40360001
Left Shift Key Up 10 c02a0001

Left Shift Key Down 10 2a0001
Left Shift Key Down 10 402a0001
Left Shift Key Down 10 402a0001
Left Shift Key Down 10 402a0001
Left Shift Key Down 10 402a0001
Left Shift Key Down 10 402a0001
Right Shift Key Down a1 40360001
Right Shift Key Down a1 40360001
Right Shift Key Down a1 40360001
Right Shift Key Down a1 40360001
Right Shift Key Down a1 40360001
Right Shift Key Down a1 40360001
Right Shift Key Down a1 40360001
Right Shift Key Down a1 40360001
Right Shift Key Up a1 c0360001


First column shows whether I am getting a WM_KEYDOWN or WM_KEYUP message.
second column shows the wParam hex value
third column shows the lParam hex value

For the first test I pressed LSHIFT, released LSHIFT, pressed RSHIFT, released RSHIFT. All okay

Second test I pressed LSHIFT and held it down, pressed RSHIFT, released RSHIFT, released LSHIFT. not okay

Last test I pressed LSHIFT and held it down, pressed RSHIFT and held it down, released LSHIFT, released RSHIFT. Also not okay

This topic is closed to new replies.

Advertisement