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.

Keyboard and VK Codes

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.

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

Format
mla apa chicago
Your Citation
Gajic, Zarko. "Virtual Key Codes Used by Windows." ThoughtCo, Aug. 26, 2020, thoughtco.com/virtual-key-codes-used-by-windows-4071289. Gajic, Zarko. (2020, August 26). Virtual Key Codes Used by Windows. Retrieved from https://www.thoughtco.com/virtual-key-codes-used-by-windows-4071289 Gajic, Zarko. "Virtual Key Codes Used by Windows." ThoughtCo. https://www.thoughtco.com/virtual-key-codes-used-by-windows-4071289 (accessed March 19, 2024).