Keystrokes and Characters

The messages that an application receives from Windows about keyboard events distinguish between ”keystrokes“ and ”characters.“ This is in accordance with the two ways you can view the keyboard. First, you can think of the keyboard as a collection of keys. The keyboard has only one A key. Pressing that key is a keystroke. Releasing that key is a keystroke. But the keyboard is also an input device that generates displayable characters. The A key can generate several characters depending on the status of the Ctrl, Shift, and Caps Lock keys. Normally, the character is a lowercase a. If the Shift key is down or Caps Lock is toggled on, the character is an uppercase A. If Ctrl is down, the character is a Ctrl-A. On a foreign-language keyboard, the A keystroke may be preceded by a ”dead-character key“ or by Shift, Ctrl, or Alt in various combinations. The combinations could generate a lowercase a or an uppercase A with an accent mark.

For keystroke combinations that result in displayable characters, Windows sends a program both keystroke messages and character messages. Some keys do not generate characters. These include the shift keys, the function keys, the cursor movement keys, and special keys such as Insert and Delete. For these keys, Windows generates only keystroke messages.