# Arbitrary key combinations & WM_CHAR [Solved]

This topic is 4032 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to get a rather spiffy keyboard input idea working. My problem is that when I press CTRL+G for instance i recieve all the WM_KEYDOWN, WM_CHAR and WM_KEYUP messages but the value of the wParam in the WM_CHAR message is ^g which is a ASCII control code and makes a beep sound when printed to the console. I would like the WM_CHAR to somehow just report the char and not the CTRL+char combo. Since I don't know what type of keyboard the player is using I can't make many assumptions on what a WM_KEYDOWN message means, except for keys like ESC or F1. E.g. US keyboards dont have åäö like Swedish ones and these get translated by Windows for me. I need a way of doing ctrl, alt or shift combos without messing up WM_CHAR or making windows beep/(play notify sounds E.g. alt+some key) so that I can rely on the value of WM_CHAR for accurate representation. This was my solution to the problem:
MSG msg;
while( GetMessage( &msg, 0, 0, 0 ) )
{
// NOTE: this will effectively cancel the effect CTRL has on TranslateMessage
// when translating WM_KEYDOWN to WM_CHAR. It's not perfect but it works!
switch( msg.message )
{
case WM_KEYDOWN:
if( msg.wParam == VK_CONTROL )
{
static BYTE keystate[0x100];
if( GetKeyState(VK_CONTROL) )
{
GetKeyboardState( keystate );
keystate[VK_CONTROL] = 0;
SetKeyboardState( keystate );
}
}
break;
}

TranslateMessage( &msg );
DispatchMessage( &msg );
}
I did however add a small pice of code in my Wnd procedure to prevent alt+some_key combos from triggering the Windows notification ding! by just adding this case.
case WM_SYSCOMMAND:
{
switch( wParam & 0xFFF0 )
{
case SC_KEYMENU:        // Process, but do nothing
return 0;           // (prevents Windows notification ding!)
}
}
break;
NOTE: If you do this you'll run into another problem, and that is that a AltGr combo (which is essential to many key combinations when typing) will not work. I've finally got to the MapVirtualKey( wParam, 2 ) function, which will return the a character representation for almost any key stroke and that it is perfect for this. Hope this helps a lot. [Edited by - leidegren on November 3, 2007 3:09:48 AM]

1. 1
Rutin
35
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633340
• Total Posts
3011421
• ### Who's Online (See full list)

There are no registered users currently online

×