For each of
these methods, you pass in a value from the Key enumeration.
Table 6-6. KeyboardDevice Methods
Name Description
IsKeyDown() Tells you whether this key was pressed down when the event occurred.
IsKeyUp() Tells you whether this key was up (not pressed) when the event
occurred.
IsKeyToggled() Tells you whether this key was in a ???switched on??? state when the event
occurred. This only has a meaning for keys that can be toggled on or
off, such as Caps Lock, Scroll Lock, and Num Lock.
GetKeyStates() Returns one or more values from the KeyStates enumeration that tell
you whether this key is currently up, pressed, or in a toggled state. This
method is essentially the same as calling both IsKeyDown() and IsKey-
Toggled() on the same key.
When you use the KeyEventArgs.KeyboardDevice property, your code gets the virtual key
state. This means it gets the state of the keyboard at the time the event occurred. This is not
necessarily the same as the current keyboard state. For example, consider what happens if the
user types faster than your code executes. Each time your KeyPress event fires, you??™ll have
access to the keystroke that fired the event, not the typed-ahead characters. This is almost
always the behavior you want.
However, you aren??™t limited to getting key information in the key events.
Pages:
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346