Skip navigation

Types of Keystroke messages Key Pressed Key Released
Nonsystem Keystroke: (Handled by WindowProc) WM_KEYDOWN WM_KEYUP
System Keystroke: (Combination of Alt key which is handled by DefWindowProc) WM_SYSKEYDOWN WM_SYSKEYUP

Scan Code: The real keyboard sends this code based on the key pressed. Hence it is too much device dependent.

Virtual Key Code: Windows has defined these codes for all keys. This is device independent. For number and alphabets the Virtual Key Codes are same as that of ASCII codes. Rest of the keys are defined in windows with different key codes.

The wParam of keystroke message contains Virtual Key Code of the key pressed. The lParam contains the following information:
1. Repeat Count – No. of keystrokes represented by the message.
2. OEM Scan Code – Not used in Windows.
3. Extended Key Flag – Represents if any additional key pressed such as right side Alt, Ctrl keys.
4. Context Code – Alt key is depressed or not.
5. Previous Key Status – This key was previously UP or DOWN.
6. Transition State – Key is being pressed or released.

GetKeyState() : This API let us to know about the status of Shift, Alt, Ctrl, Caps Lock, Num Lock & Scroll Lock keys.

Types of Character messages Characters Dead Characters
Nonsystem Characters: WM_CHAR WM_DEADCHAR

The wParam of character message contains ANSI / UNICODE Code of the key pressed. The lParam contains the information same as that of keystroke messages. IsWindowUnicode() is the API used to determine whether a window supports the UNICODE or not.

Message ordering example: Typing uppercase A by using Shift key

Message Key or Code
WM_KEYDOWN Virtual key code VK_SHIFT (0x10)
WM_KEYDOWN Virtual key code for `A’ (0x41)
WM_CHAR Character code for `A’ (0x41)
WM_KEYUP Virtual key code for `A’ (0x41)
WM_KEYUP Virtual key code VK_SHIFT (0x10)

Dead character messages: On some non-US English keyboards (like German), a diacritic concept is there. Diacritic does not generate character by themselves. They are used in combination with a letter to make a character. This key message is called dead character message.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: