Window Messages - Keyboard Input

The following Window Messages (WM_) are raised as a result of input through the keyboard (or, sometimes, the mouse).

WM_CHAR | WM_DEADCHAR | WM_HOTKEY | WM_KEYDOWN | WM_KEYUP | WM_SYSCHAR | WM_SYSDEADCHAR | WM_SYSKEYDOWN | WM_SYSKEYUP

 

WM_CHAR $0102 (258)

Posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function.

wparam value:
The character ASCII Code of the key pressed.

lparam value:
Bits 0-15 The Repeat Count - the number of times the keystroke is repeated due to the user keeping the key depressed.
Bits 16-23 The Scan Code of the key pressed.
Bit 24 Set if Extended Key* is pressed.
Bits 25-28 Reserved.
Bit 29 Set if ALT key pressed at the same time.
Bit 30 Set if this is a repeat of a previous key press.
Bit 31 Set if the key is being released.

 

WM_DEADCHAR $0103 (259)

A character code generated by a dead key which is posted to the window with the keyboard focus when a WM_KEYUP message is translated by the TranslateMessage function. A dead key is a key that generates a character, such as the umlaut (double-dot), that is combined with another character to form a composite character. For example, the umlaut-O character (Ö) is generated by typing the dead key for the umlaut character, and then typing the O key.

wparam value:
The character ASCII Code of the key pressed.

lparam value:
Bits 0-15 The Repeat Count - the number of times the keystroke is repeated due to the user keeping the key depressed.
Bits 16-23 The Scan Code of the key pressed.
Bit 24 Set if Extended Key* is pressed.
Bits 25-28 Reserved.
Bit 29 Set if ALT key pressed at the same time.
Bit 30 Set if this is a repeat of a previous key press.
Bit 31 Set if the key is being released.

 

WM_HOTKEY $0312 (786)

Posted when the user presses a hot key registered by the RegisterHotKey function.

wparam value:
The identifier of the hot key that generated the message. If the message was generated by a system-defined hot key, this parameter will be one of the following values: IDHOT_SNAPDESKTOP (-2) or IDHOT_SNAPWINDOW (-1).

lparam value:
Bits 0-15 The Scan Code of the non-'hotkey' pressed.
Bits 16-31 The hotkey(s) defined as:
    MOD_ALT($0001) - Either of the Alt keys was pressed.
    MOD_CONTROL($0002) - Either of the Ctrl keys was pressed.
    MOD_SHIFT($0004) - Either of the Shift keys was pressed.
    MOD_WIN($0008) - Either of the Windows keys was pressed.

 

WM_KEYDOWN $0100 (256)

Posted to a window when a non-system key is pressed. WM_CHAR can be used instead to return the character ASCII/ANSI code.

wparam value:
The character Key Code of the key pressed.

lparam value:
Bits 0-15 The Repeat Count - the number of times the keystroke is repeated due to the user keeping the key depressed.
Bits 16-23 The Scan Code of the key pressed.
Bit 24 Set if Extended Key* is pressed.
Bits 25-28 Reserved.
Bit 29 Always reset or 0.
Bit 30 Set if this is a repeat of a previous key press.
Bit 31 Always reset or 0.

 

WM_KEYUP $0101 (257)

Posted to a window when a non-system key is released.

wparam value:
The character Key Code of the key pressed.

lparam value:
Bits 0-15 The Repeat Count - the number of times the keystroke is repeated due to the user keeping the key depressed.
Bits 16-23 The Scan Code of the key pressed.
Bit 24 Set if Extended Key* is pressed.
Bits 25-28 Reserved.
Bit 29 Always reset or 0.
Bit 30 Always set or 1.
Bit 31 Always set or 1.

 

WM_SYSCHAR $0106 (262)

The product of WM_SYSKEYDOWN being passed through the TranslateMessage function, this returns details of the system key which was pressed.

wparam value:
The character ASCII Code of the key pressed.

lparam value:
Bits 0-15 The Repeat Count - the number of times the keystroke is repeated due to the user keeping the key depressed.
Bits 16-23 The Scan Code of the key pressed.
Bit 24 Set if Extended Key* is pressed.
Bits 25-28 Reserved.
Bit 29 Set if ALT key pressed at the same time.
Bit 30 Set if this is a repeat of a previous key press.
Bit 31 Set if the key is being released.

 

WM_SYSDEADCHAR $0107 (263)

Sent to the window with the keyboard focus when a WM_SYSKEYDOWN message is translated by the TranslateMessage function. WM_SYSDEADCHAR specifies the character code of a system dead key — that is, a dead key that is pressed while holding down the ALT key.

wparam value:
The character ASCII Code of the key pressed.

lparam value:
Bits 0-15 The Repeat Count - the number of times the keystroke is repeated due to the user keeping the key depressed.
Bits 16-23 The Scan Code of the key pressed.
Bit 24 Set if Extended Key* is pressed.
Bits 25-28 Reserved.
Bit 29 Set if ALT key pressed at the same time.
Bit 30 Set if this is a repeat of a previous key press.
Bit 31 Set if the key is being released.

 

WM_SYSKEYDOWN $0104 (260)

Posted to a window when a system key is pressed. WM_SYSCHAR can be used instead to return the character ASCII/ANSI code.

wparam value:
The character Key Code of the key pressed.

lparam value:
Bits 0-15 The Repeat Count - the number of times the keystroke is repeated due to the user keeping the key depressed.
Bits 16-23 The Scan Code of the key pressed.
Bit 24 Set if Extended Key* is pressed.
Bits 25-28 Reserved.
Bit 29 Set if ALT key pressed at the same time.
Bit 30 Set if this is a repeat of a previous key press.
Bit 31 Always reset or 0.

 

WM_SYSKEYUP $0105 (261)

Posted to a window when a system key is released.

wparam value:
The character Key Code of the key pressed.

lparam value:
Bits 0-15 The Repeat Count - the number of times the keystroke is repeated due to the user keeping the key depressed.
Bits 16-23 The Scan Code of the key pressed.
Bit 24 Set if Extended Key* is pressed.
Bits 25-28 Reserved.
Bit 29 Set if ALT key pressed at the same time.
Bit 30 Always set or 1.
Bit 31 Always set or 1.

* Extended Keys are: the right ALT and the right CTRL keys on the main section of the keyboard; the INS, DEL, HOME, END, PAGE UP, PAGE DOWN and arrow keys in the clusters to the left of the numeric keypad; and the divide (/) and ENTER keys in the numeric keypad.

† A system key event is triggered either by pressing F10, having the Alt key held down while pressing another key or when no window currently has the keyboard focus.

‡ The code for the actual key, not character, pressed on the keyboard which is then translated into a key code or ASCII value.

{Created by Sjouke Hamstra; Last updated: 12/05/14 by James Gaite}