KEYSTROKE MESSAGES

When you press a key, Windows places either a WM_KEYDOWN or WM_SYSKEYDOWN message in the message queue of the window with the input focus. When you release a key, Windows places either a WM_KEYUP or WM_SYSKEYUP message in the message queue.

  Key Pressed Key Released

Nonsystem Keystroke: WM_KEYDOWN WM_KEYUP
System Keystroke: WM_SYSKEYDOWN WM_SYSKEYUP

Usually the ”down“ and ”up“ messages occur in pairs. However, if you hold down a key so that the typematic (autorepeat) action takes over, Windows sends the window procedure a series of WM_KEYDOWN (or WM_SYSKEYDOWN) messages and a single WM_KEYUP (or WM_SYSKEYUP) message when the key is finally released. Like all messages, keystroke messages are time-stamped. You can obtain the relative time a key was pressed or released by calling GetMessageTime.