Game Development Reference
In-Depth Information
'
The VK_F1 is a #define in WinUser.h, where you
ll find definitions for every
other virtual key you ' ll need: VK_ESCAPE , VK_TAB , VK_SPACE , and so on.
Processing different keyboard inputs seems messy, doesn
tit?Holdon,itgetsbetter.The
next sequence shows the left Shift key, right Shift key, left Ctrl key, and right Ctrl key:
'
WM_KEYDOWN
Code: 16
'
_
'
Repeat:1 Oem:42 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:0
WM_KEYUP
Code: 16
'
_
'
Repeat:1 Oem:42 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:1
WM_KEYDOWN
Code: 16
'
_
'
Repeat:1 Oem:54 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:0
WM_KEYUP
Code: 16
'
_
'
Repeat:1 Oem:54 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:1
WM_KEYDOWN
Code: 17
'
_
'
Repeat:1 Oem:29 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:0
WM_KEYUP
Code: 17
'
_
'
Repeat:1 Oem:29 Ext
'
d:0 IsAlt:0 WasDown:0 Rel
'
d:1
WM_KEYDOWN
Code: 17
'
_
'
Repeat:1 Oem:29 Ext
'
d:1 IsAlt:0 WasDown:0 Rel
'
d:0
WM_KEYUP
d:1
The only way to distinguish the left Shift key from the right Shift key is to look at the
OEM scan code. On the other hand, the only way to distinguish the left Ctrl key
from the right Ctrl key is to look at the extended key bit to see if it is set for the
right Ctrl key. This insane cobbler of aggregate design is the best example of what
happens if you have a mandate to create new technology while supporting stuff as
old as my high school diploma (or is that my grade school one?).
Code: 17
'
_
'
Repeat:1 Oem:29 Ext
'
d:1 IsAlt:0 WasDown:0 Rel
'
You Might Need Your Own Keyboard Handler
To get around the problems of processing keyboard inputs that look the same
as I
ll want to write your own handler for
accepting the WM_KEYDOWN and WM_KEYUP messages. If your game is going
to have a complicated enough interface to distinguish between left and right
Ctrl or Shift keys and will use these keys in combination with others, you
'
ve outlined in this section, you
'
ve
got an interesting road ahead. My best advice is to try to keep things as
simple as possible. It
'
s a bad idea to assign different actions to both Ctrl or
Shift keys anyway. If your game only needs some hot keys and no fancy
combinations, WM_KEYDOWN will work fine all by itself.
'
Here ' s a summary of how to get the right data out of these keyboard messages:
n WM_CHAR : Use this message only if your game cares about printable characters:
no function keys, Ctrl keys, or Shift keys as a single input.
n WM_KEYDOWN/WM_KEYUP : Grabs each key as you press it, but makes no distinction
between upper- and lowercase characters. Use this to grab function key input and
compare the OEM scan codes with MapVirtualKey() .Youwon
t get upper-
and lowercase characters without tracking the status of the Shift keys yourself.
'
It
'
s almost like this system was engineered by a congressional conference committee.
Search WWH ::




Custom Search