Virtual Key codes provide a symbolic representation of user key presses.

 

Unit

 

Windows

 

Description

 

Virtual key codes allow you to represent keyboard values for non-alphanumeric keys.Windows defines special constants for each key the user can press. These constants can then be used to refer to the keystroke in Windows API calls or in an OnKeyUp or OnKeyDown event handler.

 

Most of the virtual key codes are defined in the Windows unit. Additional key codes may be defined in special-purpose Windows wrappers such as the imm unit. For alphabetic keys, you should use ord with an uppercase character, for example, ord( 'M' ). To create a virtual key code for an alphanumeric value, use the Ord method. For example the virtual key code for ‘7’ is Ord(‘

7’).

 

The following table lists the virtual key codes defined in the Windows unit:

 

Virtual Key Code        Corresponding key

 

VK_LBUTTON          Left mouse button

VK_RBUTTON         Right mouse button

VK_CANCEL            Control+Break

VK_MBUTTON        Middle mouse button

VK_BACK     Backspace key

VK_TAB        Tab key

VK_CLEAR   Clear key

VK_RETURN Enter key

VK_SHIFT     Shift key

VK_CONTROL         Ctrl key

VK_MENU    Alt key

VK_PAUSE    Pause key

VK_CAPITAL           Caps Lock key

VK_KANA    Used with IME

VK_HANGUL           Used with IME

VK_JUNJA    Used with IME

VK_FINAL    Used with IME

VK_HANJA   Used with IME

VK_KANJI    Used with IME

VK_CONVERT         Used with IME

 

VK_NONCONVERT            Used with IME

VK_ACCEPT Used with IME

VK_MODECHANGE            Used with IME

VK_ESCAPE Esc key

VK_SPACE    Space bar

VK_PRIOR    Page Up key

VK_NEXT      Page Down key

VK_END        End key

VK_HOME    Home key

VK_LEFT       Left Arrow key

VK_UP           Up Arrow key

VK_RIGHT    Right Arrow key

VK_DOWN   Down Arrow key

VK_SELECT  Select key

VK_PRINT     Print key (keyboard-specific)

VK_EXECUTE          Execute key

VK_SNAPSHOT       Print Screen key

VK_INSERT  Insert key

VK_DELETE  Delete key

VK_HELP      Help key

 

VK_LWIN      Left Windows key (Microsoft keyboard)

VK_RWIN     Right Windows key (Microsoft keyboard)

VK_APPS      Applications key (Microsoft keyboard)

VK_NUMPAD0         0 key (numeric keypad)

VK_NUMPAD1         1 key (numeric keypad)

VK_NUMPAD2         2 key (numeric keypad)

VK_NUMPAD3         3 key (numeric keypad)

VK_NUMPAD4         4 key (numeric keypad)

VK_NUMPAD5         5 key (numeric keypad)

VK_NUMPAD6         6 key (numeric keypad)

VK_NUMPAD7         7 key (numeric keypad)

VK_NUMPAD8         8 key (numeric keypad)

VK_NUMPAD9         9 key (numeric keypad)

 

VK_MULTIPLY        Multiply key (numeric keypad)

VK_ADD        Add key (numeric keypad)

VK_SEPARATOR     Separator key (numeric keypad)

VK_SUBTRACT        Subtract key (numeric keypad)

VK_DECIMAL          Decimal key (numeric keypad)

VK_DIVIDE   Divide key (numeric keypad)

VK_F1            F1 key

VK_F2            F2 key

VK_F3            F3 key

VK_F4            F4 key

VK_F5            F5 key

VK_F6            F6 key

VK_F7            F7 key

VK_F8            F8 key

VK_F9            F9 key

VK_F10          F10 key

VK_F11          F11 key

VK_F12          F12 key

VK_F13          F13 key

VK_F14          F14 key

VK_F15          F15 key

 

VK_F16          F16 key

VK_F17          F17 key

VK_F18          F18 key

VK_F19          F19 key

VK_F20          F20 key

VK_F21          F21 key

VK_F22          F22 key

VK_F23          F23 key

VK_F24          F24 key

VK_NUMLOCK       Num Lock key

VK_SCROLL Scroll Lock key

VK_LSHIFT   Left Shift key (only used with GetAsyncKeyState and GetKeyState)

VK_RSHIFT   Right Shift key (only used with GetAsyncKeyState and GetKeyState)

VK_LCONTROL       Left Ctrl key (only used with GetAsyncKeyState and GetKeyState)

VK_RCONTROL      Right Ctrl key (only used with GetAsyncKeyState and GetKeyState)

 

VK_LMENU  Left Alt key (only used with GetAsyncKeyState and GetKeyState)

VK_RMENU  Right Alt key (only used with GetAsyncKeyState and GetKeyState)

VK_PROCESSKEY  Process key

VK_ATTN      Attn key

VK_CRSEL    CrSel key

VK_EXSEL    ExSel key

VK_EREOF    Erase EOF key

VK_PLAY      Play key

VK_ZOOM    Zoom key

VK_NONAME          Reserved for future use

VK_PA1         PA1 key

VK_OEM_CLEAR    Clear key

 

 

 

 

The following code aborts a print job if the user presses Esc. Note that you should setKeyPreview to True to ensure that the OnKeyDown event handler of Form1 is called.

 

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

begin

if (Key=VK_ESCAPE) and Printer.Printing then

  begin

  Printer.Abort;

  MessageDlg('Printing aborted', mtInformation, [mbOK],0);

  end;

 

end;

 

 

­­­

INNA WERSJA

 

community.borland.com

Article #15546: Lists the virtual key values

 Technical Information Database
 
TI546D.txt   Lists the virtual key values
Category   :Windows API
Platform    :All
Product    :Delphi  All
 
Description:
Q:  What are the values for the virtual keys?
 
A:
 
  vk_LButton   = $01;
  vk_RButton   = $02;
  vk_Cancel    = $03;
  vk_MButton   = $04;   { NOT contiguous with L & RBUTTON }
  vk_Back      = $08;
  vk_Tab       = $09;
  vk_Clear     = $0C;
  vk_Return    = $0D;
  vk_Shift     = $10;
  vk_Control   = $11;
  vk_Menu      = $12;
  vk_Pause     = $13;
  vk_Capital   = $14;
  vk_Escape    = $1B;
  vk_Space     = $20;
  vk_Prior     = $21;
  vk_Next      = $22;
 
  vk_End       = $23;
  vk_Home      = $24;
  vk_Left      = $25;
  vk_Up        = $26;
  vk_Right     = $27;
  vk_Down      = $28;
  vk_Select    = $29;
  vk_Print     = $2A;
  vk_Execute   = $2B;
  vk_SnapShot  = $2C;
{ vk_Copy      = $2C not used by keyboards }
  vk_Insert    = $2D;
  vk_Delete    = $2E;
  vk_Help      = $2F;
{ vk_A thru vk_Z are the same as their ASCII equivalents: 'A' thru 'Z' }
{ vk_0 thru vk_9 are the same as their ASCII equivalents: '0' thru '9' }
 
  vk_NumPad0   = $60;
  vk_NumPad1   = $61;
  vk_NumPad2   = $62;
  vk_NumPad3   = $63;
  vk_NumPad4   = $64;
  vk_NumPad5   = $65;
  vk_NumPad6   = $66;
  vk_NumPad7   = $67;
  vk_NumPad8   = $68;
  vk_NumPad9   = $69;
  vk_Multiply  = $6A;
  vk_Add       = $6B;
  vk_Separator = $6C;
  vk_Subtract  = $6D;
  vk_Decimal   = $6E;
  vk_Divide    = $6F;
  vk_F1        = $70;
  vk_F2        = $71;
  vk_F3        = $72;
  vk_F4        = $73;
  vk_F5        = $74;
 
  vk_F6        = $75;
  vk_F7        = $76;
  vk_F8        = $77;
  vk_F9        = $78;
  vk_F10       = $79;
  vk_F11       = $7A;
  vk_F12       = $7B;
  vk_F13       = $7C;
  vk_F14       = $7D;
  vk_F15       = $7E;
  vk_F16       = $7F;
  vk_F17       = $80;
  vk_F18       = $81;
  vk_F19       = $82;
  vk_F20       = $83;
  vk_F21       = $84;
  vk_F22       = $85;
  vk_F23       = $86;
  vk_F24       = $87;
  vk_NumLock   = $90;
  vk_Scroll    = $91;
 
 
 
Reference:
 
 
7/16/98 4:33:47 PM
 

Last Modified: 01-SEP-99