Skip to content

Instantly share code, notes, and snippets.

@artem78
Last active April 10, 2026 18:05
Show Gist options
  • Select an option

  • Save artem78/fa5a72b570130e5ef78d14d6b4943d05 to your computer and use it in GitHub Desktop.

Select an option

Save artem78/fa5a72b570130e5ef78d14d6b4943d05 to your computer and use it in GitHub Desktop.
{$MODE objfpc}
program laz_key_ids;
uses sysutils, classes, lclproc, LCLType, StrUtils,LazVersion;
const
Col1Width = 10;
Col2Width = 20;
Col3Width = 17;
var
Key: Word;
KeyIdentifier, KeyName: String;
begin
writeln('Table of key names (identifiers) returned by [KeyAndShiftStateToKeyString]'
+ '(https://lazarus-ccr.sourceforge.io/docs/lcl/lclproc/keyandshiftstatetokeystring.html) '
+ 'function in Lazarus ' + laz_version);
writeln('|', 'Key code':Col1Width, '|', 'Key identifier':Col2Width , '|', 'Description':Col3Width, '|');
writeln('|', StringOfChar('-',Col1Width),'|',StringOfChar('-',Col2Width),'|',StringOfChar('-',Col3Width),'|');
for Key := VK_BACK to VK_SCROLL do
// VK_BROWSER_BACK to VK_OEM_CLEAR
begin
KeyIdentifier := KeyAndShiftStateToKeyString(Key, []);
if KeyStringIsIrregular(KeyIdentifier) then
Continue; // Skip unknown (unused) key codes
KeyName := '';
case Key of
VK_BACK: KeyName := 'Backspace';
VK_NUMPAD0..VK_NUMPAD9: KeyName := 'Numpad ' + IntToStr(Key - VK_NUMPAD0);
VK_MULTIPLY: KeyName := 'Numpad *';
VK_ADD: KeyName := 'Numpad +';
VK_SEPARATOR: KeyName := 'Numpad Separator'; // what is this?
VK_SUBTRACT: KeyName := 'Numpad -';
VK_DECIMAL: KeyName := 'Numpad . (Del)';
VK_DIVIDE: KeyName := 'Numpad /';
VK_RETURN: KeyName := 'Enter and Numpad Enter';
VK_PRIOR: KeyName := 'Page Up';
VK_NEXT: KeyName := 'Page Down';
VK_APPS : KeyName := '[Menu (application) key](https://en.wikipedia.org/wiki/Menu_key)';
end;
writeln('|', Key:Col1Width, '|', KeyIdentifier:Col2Width ,'|', KeyName: Col3Width, '|')
end;
end.

Table of key names (identifiers) returned by KeyAndShiftStateToKeyString function in Lazarus 2.2.4.0

Key code Key identifier Description
8 BkSp Backspace
9 Tab
12 NumClear
13 Enter Enter and Numpad Enter
19 Break
20 CapsLock
21 IME_Kana
23 IME_Junja
24 IME_final
25 IME_Hanja
27 Esc
28 IME_convert
29 IME_nonconvert
30 IME_accept
31 IME_mode_change
32 Space
33 PgUp Page Up
34 PgDn Page Down
35 End
36 Home
37 Left
38 Up
39 Right
40 Down
41 Select
42 Print
43 Execute
44 PrintScreen
45 Ins
46 Del
47 Help
48 0
49 1
50 2
51 3
52 4
53 5
54 6
55 7
56 8
57 9
65 A
66 B
67 C
68 D
69 E
70 F
71 G
72 H
73 I
74 J
75 K
76 L
77 M
78 N
79 O
80 P
81 Q
82 R
83 S
84 T
85 U
86 V
87 W
88 X
89 Y
90 Z
93 PopUp Menu (application) key
95 Sleep
96 Num0 Numpad 0
97 Num1 Numpad 1
98 Num2 Numpad 2
99 Num3 Numpad 3
100 Num4 Numpad 4
101 Num5 Numpad 5
102 Num6 Numpad 6
103 Num7 Numpad 7
104 Num8 Numpad 8
105 Num9 Numpad 9
106 NumMul Numpad *
107 NumPlus Numpad +
108 NumSepar Numpad Separator
109 NumMinus Numpad -
110 NumDot Numpad . (Del)
111 NumDiv Numpad /
112 F1
113 F2
114 F3
115 F4
116 F5
117 F6
118 F7
119 F8
120 F9
121 F10
122 F11
123 F12
124 F13
125 F14
126 F15
127 F16
128 F17
129 F18
130 F19
131 F20
132 F21
133 F22
134 F23
135 F24
144 NumLock
145 ScrollLock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment