Game Development Reference
In-Depth Information
WM_KEYUP
Code:113
'
q
'
Repeat:1 Oem:60 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:1
WM_KEYDOWN
Code:114
'
r
'
Repeat:1 Oem:61 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:0
WM_KEYUP
Code:114
'
r
'
Repeat:1 Oem:61 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:1
WM_KEYDOWN
Code: 16
'
_
'
Repeat:1 Oem:42 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:0
WM_KEYDOWN
Code:112
'
p
'
Repeat:1 Oem:59 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:0
WM_KEYUP
Code:112
'
p
'
Repeat:1 Oem:59 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:1
WM_KEYDOWN
Code:113
'
q
'
Repeat:1 Oem:60 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:0
WM_KEYUP
Code:113
'
q
'
Repeat:1 Oem:60 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:1
WM_KEYDOWN
Code:114
'
r
'
Repeat:1 Oem:61 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:0
WM_KEYUP
Code:114
'
r
'
Repeat:1 Oem:61 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:1
WM_KEYUP
Code: 16
'
_
'
Repeat:1 Oem:42 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:1
There
t there? Also, notice that the code
returned by the F1 key is the same as the lowercase
'
s a distinct lack of WM_CHAR messages, isn
'
p
character. So, what does
p
look like?
WM_KEYDOWN
Code: 80
'
P
'
Repeat:1 Oem:25 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:0
WM_CHAR
Code:112
'
p
'
Repeat:1 Oem:25 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:0
WM_KEYUP
d:1
Isn ' t that interesting? The virtual scan code for p as encoded for WM_CHAR is
exactly the same as the code for WM_KEYUP and WM_KEYDOWN . This funky design
leads to some buggy misinterpretations of these two messages if you are looking at
nothing but the virtual scan code. I
Code: 80
'
P
'
Repeat:1 Oem:25 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
ve seen some games where you could use the
function keys to enter your character name!
'
Function Keys Require Special Handling
You can
t use WM_CHAR to grab function key input or any other keyboard key
not associated with a typeable character. It is confusing that the ASCII value for
the lowercase
'
p
character is also the VK_F1 .
If you were beginning to
suspect that you couldn
'
t use the wParam value from all these messages in
the same way, you
'
re right.
If you want to figure out the difference between keys, you should use the OEM scan
code. There
'
s a Windows helper function to translate it into something useful:
// grab bits 16-23 from LPARAM
unsigned int oemScan = int(lParam & (0xff << 16))>>16;
UINT vk = MapVirtualKey(oemScan, 1);
if (vk == VK_F1)
{
// we've got someone pressing the F1 key!
}
 
Search WWH ::




Custom Search