Date: 02-16-2022
Return to Index
created by gbSnippets
'Bottom Line: Keystrokes are captured by the control window procedures and
' are often not available in the dialog/control callback procedures
'Work Around: Subclass the control to get access to the message
'Once you've subclassed - use %WM_Char for most keystroke needs
' Applications that process keyboard input typically ignore all but the WM_CHAR
' Applications typically ignore Scan codes, instead using virtual-key codes.
Keyboard Input Model
'Each key is assigned a Scan Code. A keyboard generates two scan codes, one when
'the user presses the key AND another when the user releases the key.
'The keyboard device driver translates scan code to virtual-key Code, then sends a
'message with scan code, virtual-key code, and other information about the keystroke.
'System keystroke is when ALT pressed with other key.
'Dead keys are used to add diacritic to character produced by the subsequent keystroke.
'Messages/Functions-------------------------
Messages Functions
WM_KeyDown WM_SysKeyDown SendInput
WM_KeyUp WM_SysKeyUp keyb_event
WM_Char WM_SysDeadChar RegisterHotKey
WM_DeadChar UnRegisterHotKey
WM_AppCommand GetKeyState
WM_KillFocus GetAsyncKeyState
WM_SetFocus SetFocus
WM_Activate GetFocus
WM_HotKey SetActiveWindow
GetActiveWindow
'Descriptions-------------------------------
SendInput 'synthesizes keystrokes, mouse motions, and button clicks
keyb_event 'synthesizes a keystroke
RegisterHotKey 'defines a system-wide hot key
UnRegisterHotKey 'releases a system-wide hot key
GetKeyState 'determine the status of a virtual key at the time the current message was generated
GetAsyncKeyState 'retrieve the current status of a virtual key.
GetFocus 'returns which window has keyboard focus
SetFocus 'is used to give a window the keyboard focus.
SetActiveWindow 'gives a window active status
GetActiveWindow 'returns handle of currently active window
WM_KeyDown 'caused by pressing a key
WM_KeyUp 'releasing a key
WM_Char 'when a WM_KeyDown message is processed
WM_DeadChar 'for a dead key, when a WM_KeyUp is processed
WM_SysKeyDown 'caused by pressing a Alt+key
WM_SysKeyUp 'releasing a Alt-key
WM_SysDeadChar 'for a dead key, when a WM_SysKeyDown is processed
WM_APPCOMMAND 'special keys: browser, media, application launching, power management
WM_KillFocus 'sent to window that has lost focus when focus changes
WM_SetFocus 'sent to window that has gained focus when focus changes
WM_Activate 'sent to Window being activated AND the Window being deactivated
'low-order word of the wParam parameter is zero if the
'Window is being deactivated AND nonzero if it is being activated.
WM_HotKey 'from hot key, priority message (such as Ctrl-C to cancel operation)
.Message wParam/lParam
'And finally, here are the wParam/lParm makeup of the messages.
-----------------------------------------------------
WM_Char ' w character code
' l repeat, scan, xtFlag, context, previous, state
-----------------------------------------------------
WM_KeyUp ' w virtual-key code
' l repeat, scan, xtFlag, context, previous, state
-----------------------------------------------------
WM_KeyDown ' w virtual-key code
' l repeat, scan, xtFlag, context, previous, state
-----------------------------------------------------
WM_SysKeyUp ' w Alt+virtual-key code
' l repeat, scan, xtFlag, context, previous, state
-----------------------------------------------------
WM_SysKeyDown ' w Alt+virtual-key code
' l repeat, scan, xtFlag, context, previous, state
-----------------------------------------------------
WM_DeadChar ' w dead key character code
' l repeat, scan, xtFlag, context, previous, state
-----------------------------------------------------
WM_SysDeadChar ' w Alt+dead key character code
' l repeat, scan, xtFlag, context, previous, state
-----------------------------------------------------
WM_AppCommand ' w handle to window where mouse was clicked
' l code for keyboard application command/device/keys
-----------------------------------------------------
WM_KillFocus ' w handle to window that lost focus
' l not used
-----------------------------------------------------
WM_SetFocus ' w handle to window
' l not used
-----------------------------------------------------
WM_Activate ' w whether window is being activated or deactivated
' l handle to window being activated/deactivated
-----------------------------------------------------
WM_HotKey ' w hot key identifier
' l Lo flag: ctrl/alt/shift/Window keys pressed
' Hi virtual key code of hot key
'gbs_00188
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm