Virtual Key Codes Used by Windows

Business Concepts
Biggie Productions/The Image Bank/Getty Images

Windows defines special constants for each key the user can press. The virtual-key codes identify various virtual keys. These constants can then be used to refer to the keystroke when using Delphi and Windows API calls or in an OnKeyUp or OnKeyDown event handler. Virtual keys mainly consist of actual keyboard keys, but also include "virtual" elements such as the three mouse buttons. Delphi defines all constants for Windows virtual key codes in the Windows unit.

Here are some of the Delphi articles that deal with the keyboard and VK codes:

Keyboard Symphony
Delphi For Beginners: Get familiar with the OnKeyDown, OnKeyUp, and onKeyPress event procedures to respond to various key actions or handle and process ASCII characters along with other special purpose keys.

How to Translate a Virtual Key Code into a Character
Windows defines special constants for each key the user can press. The virtual-key codes identify various virtual keys. In Delphi, the OnKeyDown and OnKeyUp events provide the lowest level of keyboard response. To use OnKeyDown or OnKeyUp to test for keys the user presses, you must use Virtual key codes to get the key pressed. Here's how to translate the virtual key code to the corresponding Windows character.

Touch Me - I'm Untouchable
Intercepting keyboard input for controls that cannot receive the input focus. Working with keyboard hooks from Delphi.

ENTERing Tab
Using the Enter key like a Tab key with Delphi controls.

Abort a Loop by Pressing a Key
Use the VK_ESCAPE to abort a (for) loop.

Use Arrow Keys to Move Between Controls
The UP and DOWN arrow keys are virtually useless in edit controls. So why not use them for navigating between fields.

Shift, Ctrl, Alt Key Checking
Using virtual key codes to check the key state.

Simulating Keystrokes from Code
A handy function to simulate the pressing of keyboard keys.

The following table shows the symbolic constant names, hexadecimal values, and keyboard equivalents for the virtual-key codes used by Windows. Some Windows 2000 and OEM specific constants are missing, the entire list is available from Microsoft. The codes are listed in numerical order.

Symbolic
constant name
Value
(hexadecimal)
Keyboard (or mouse) equivalent
VK_LBUTTON01Left mouse button
VK_RBUTTON02Right mouse button
VK_CANCEL03Control-break processing
VK_MBUTTON04Middle mouse button (three-button mouse)
VK_BACK08BACKSPACE key
VK_TAB09TAB key
VK_CLEAR0CCLEAR key
VK_RETURN0DENTER key
VK_SHIFT10SHIFT key
VK_CONTROL11CTRL key
VK_MENU12ALT key
VK_PAUSE13PAUSE key
VK_CAPITAL14CAPS LOCK key
VK_ESCAPE1BESC key
VK_SPACE20SPACEBAR
VK_PRIOR21PAGE UP key
VK_NEXT22PAGE DOWN key
VK_END23END key
VK_HOME24HOME key
VK_LEFT25LEFT ARROW key
VK_UP26UP ARROW key
VK_RIGHT27RIGHT ARROW key
VK_DOWN28DOWN ARROW key
VK_SELECT29SELECT key
VK_PRINT2APRINT key
VK_EXECUTE2BEXECUTE key
VK_SNAPSHOT2CPRINT SCREEN key
VK_INSERT2DINS key
VK_DELETE2EDEL key
VK_HELP2FHELP key
 300 key
 311 key
 322 key
 333 key
 344 key
 355 key
 366 key
 377 key
 388 key
 399 key
 41A key
 42B key
 43C key
 44D key
 45E key
 46F key
 47G key
 48H key
 49I key
 4AJ key
 4BK key
 4CL key
 4DM key
 4EN key
 4FO key
 50P key
 51Q key
 52R key
 53S key
 54T key
 55U key
 56V key
 57W key
 58X key
 59Y key
 5AZ key
VK_NUMPAD060Numeric keypad 0 key
VK_NUMPAD161Numeric keypad 1 key
VK_NUMPAD262Numeric keypad 2 key
VK_NUMPAD363Numeric keypad 3 key
VK_NUMPAD464Numeric keypad 4 key
VK_NUMPAD565Numeric keypad 5 key
VK_NUMPAD666Numeric keypad 6 key
VK_NUMPAD767Numeric keypad 7 key
VK_NUMPAD868Numeric keypad 8 key
VK_NUMPAD969Numeric keypad 9 key
VK_SEPARATOR6CSeparator key
VK_SUBTRACT6DSubtract key
VK_DECIMAL6EDecimal key
VK_DIVIDE6FDivide key
VK_F170F1 key
VK_F271F2 key
VK_F372F3 key
VK_F473F4 key
VK_F574F5 key
VK_F675F6 key
VK_F776F7 key
VK_F877F8 key
VK_F978F9 key
VK_F1079F10 key
VK_F117AF11 key
VK_F127BF12 key
VK_F137CF13 key
VK_F147DF14 key
VK_F157EF15 key
VK_F167FF16 key
VK_F1780HF17 key
VK_F1881HF18 key
VK_F1982HF19 key
VK_F2083HF20 key
VK_F2184HF21 key
VK_F2285HF22 key
VK_F2386HF23 key
VK_F2487HF24 key
VK_NUMLOCK90NUM LOCK key
VK_SCROLL91SCROLL LOCK key
VK_LSHIFTA0Left SHIFT key
VK_RSHIFTA1Right SHIFT key
VK_LCONTROLA2Left CONTROL key
VK_RCONTROLA3Right CONTROL key
VK_LMENUA4Left MENU key
VK_RMENUA5Right MENU key
VK_PLAYFAPlay key
VK_ZOOMFBZoom key