Representing Keys and Shortcuts
Go Up to Using the RTL in Multi-Device Applications
This page explains the different ways that you may use to represent keys or shortcuts (combinations of keys).
Contents
- 1 Representing Keys
- 1.1 Representing Letter Keys
- 1.2 Representing Digit Keys
- 1.3 Representing Symbol Keys
- 1.4 Representing Editing Keys
- 1.5 Representing Navigation Keys
- 1.6 Representing Modifier Keys
- 1.7 Representing Function Keys
- 1.8 Representing Lock Keys
- 1.9 Representing Numeric Pad Keys
- 1.10 Representing Multimedia Keys
- 1.11 Representing Buttons
- 1.12 Representing Language Input Keys
- 1.13 Representing Other Keys
- 2 Representing Shortcuts
- 3 Specifying Accelerator Keys
- 4 Switching Between Code and String Representation
- 5 See Also
Representing Keys
To represent a single key, you may use either a code or a string. The following tables show a complete list of codes and strings that you may use to represent each key.
The following tables do not show a string representation for some keys because the UI framework is not responsible for the string representation of those keys. Instead, the operating system where your application is running provides the string representation of those keys. The following tables do not show those string representations provided by the operating system because they may vary; for example, Windows provides locale-specific key names.
Representing Letter Keys
Key | Code Representation | String Representation |
---|---|---|
Constant (System.UITypes) | String | |
|
|
A |
|
|
B |
|
|
C |
|
|
D |
|
|
E |
|
|
F |
|
|
G |
|
|
H |
|
|
I |
|
|
J |
|
|
K |
|
|
L |
|
|
M |
|
|
N |
|
|
O |
|
|
P |
|
|
Q |
|
|
R |
|
|
S |
|
|
T |
|
|
U |
|
|
V |
|
|
W |
|
|
X |
|
|
Y |
|
|
Z |
Representing Digit Keys
Key | Code Representation | String Representation |
---|---|---|
Constant (System.UITypes) | String | |
|
|
0 |
|
|
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
Representing Symbol Keys
Key | Code Representation | String Representation |
---|---|---|
Constant (System.UITypes) | String | |
Backslash |
|
\ |
Bracket (Opening) |
|
[ |
Bracket (Closing) |
|
] |
Comma |
|
, |
Equal sign |
|
= |
Minus sign |
|
- |
Period |
|
. |
Quote |
|
' |
Semicolon |
|
; |
Slash |
|
/ |
Tilde |
|
~ |
Representing Editing Keys
Key | Code Representation | String Representation | |
---|---|---|---|
Constant (System.UITypes) | Constant (FMX.Consts, Vcl.Consts) | String | |
|
|
|
BkSp |
|
|
|
Del |
|
|
|
Enter |
|
|
|
Ins |
|
|
|
Space |
|
|
|
Tab |
Key | Code Representation | String Representation | |
---|---|---|---|
Constant (System.UITypes) | Constant (FMX.Consts, Vcl.Consts) | String | |
|
|
|
Esc |
|
|
|
PgUp |
|
|
|
PgDn |
|
|
|
End |
|
|
|
Home |
|
|
|
Left |
|
|
|
Up |
|
|
|
Right |
|
|
|
Down |
Representing Modifier Keys
Key | Code Representation | String Representation | |
---|---|---|---|
System.Classes Constant | Constant (FMX.Consts, Vcl.Consts) | String | |
|
|
|
|
|
|
|
|
|
|
|
|
| |||
|
|
|
|
Most computers running Windows do not have a CMD
key, just as most computers running macOS do not have a CTRL
key. Mind this when you configure the shortcuts of your application. You may need to define your shortcuts at run time and use conditional compilation to set the right shortcut for each platform. For example:
Delphi:
{$IF defined(MSWINDOWS)}
MenuItem1.ShortCut := TextToShortCut('Ctrl+N');
{$ELSEIF defined(MACOS) and not defined(IOS)}
MenuItem1.ShortCut := TextToShortCut('Cmd+N');
{$ENDIF}
C++:
#if defined(_WIN32)
MenuItem1->ShortCut = TextToShortCut("Ctrl+N");
#elif defined(__APPLE__) && (defined(__i386__) or defined(__x86_64__))
MenuItem1->ShortCut = TextToShortCut("Cmd+N");
#endif
You may also represent modifier keys as regular keys using the following constants and strings:
Key | Code Representation | String Representation | |
---|---|---|---|
Constant (System.UITypes) | Constant (FMX.Consts) | String | |
|
|
Alt | |
|
|
|
Left Alt |
|
|
|
Right Alt |
|
|
Ctrl | |
|
|
|
Left Ctrl |
|
|
|
Right Ctrl |
|
|
Shift | |
|
|
|
Left Shift |
|
|
|
Right Shift |
|
|
|
Left Win |
|
|
|
Right Win |
Representing Function Keys
Key | Code Representation | String Representation |
---|---|---|
Constant (System.UITypes) | String | |
|
|
F1 |
|
|
F2 |
|
|
F3 |
|
|
F4 |
|
|
F5 |
|
|
F6 |
|
|
F7 |
|
|
F8 |
|
|
F9 |
|
|
F10 |
|
|
F11 |
|
|
F12 |
|
|
F13 |
|
|
F14 |
|
|
F15 |
|
|
F16 |
|
|
F17 |
|
|
F18 |
|
|
F19 |
|
|
F20 |
|
|
F21 |
|
|
F22 |
|
|
F23 |
|
|
F24 |
Representing Lock Keys
Key | Code Representation | String Representation | |
---|---|---|---|
Constant (System.UITypes) | Constant (FMX.Consts) | String | |
|
|
|
Caps Lock |
|
|
|
Num Lock |
|
|
|
Scroll Lock |
Representing Numeric Pad Keys
Key | Code Representation | String Representation |
---|---|---|
Constant (System.UITypes) | String | |
|
|
Num 0 |
|
|
Num 1 |
|
|
Num 2 |
|
|
Num 3 |
|
|
Num 4 |
|
|
Num 5 |
|
|
Num 6 |
|
|
Num 7 |
|
|
Num 8 |
|
|
Num 9 |
|
|
Num * |
|
|
Num + |
|
|
Num , |
|
|
Num - |
|
|
Num . |
|
|
Num / |
Representing Multimedia Keys
Key | Code Representation | String Representation | |
---|---|---|---|
Constant (System.UITypes) | Constant (FMX.Consts) | String | |
Browser: Back |
|
|
BrowserBack |
Browser: Forward |
|
||
Browser: Refresh |
|
||
Browser: Stop |
|
||
Browser: Search |
|
||
Browser: Favorites |
|
||
Browser: Home |
|
||
Camera |
|
|
Camera |
Launch: Email |
|
||
Launch: Media Select |
|
||
Launch: App 1 |
|
||
Launch: App 2 |
|
||
Media: Next track |
|
||
Media: Previous track |
|
||
Media: Stop |
|
||
Media: Play/Pause |
|
||
Volume: Mute |
|
||
Volume: Down |
|
||
Volume: Up |
|
Representing Buttons
Button | Code Representation |
---|---|
Constant (System.UITypes) | |
Left mouse button |
|
Right mouse button |
|
Middle mouse button |
|
X1 mouse button |
|
X2 mouse button |
|
Representing Language Input Keys
Key | Code Representation |
---|---|
IME Kana mode |
|
IME Hangul mode |
|
IME Junja mode |
|
IME final mode |
|
IME Hanja mode |
|
IME Kanji mode |
|
IME convert |
|
IME nonconvert |
|
IME accept |
|
IME mode change request |
|
IME process |
|
Representing Other Keys
Key | Code Representation | String Representation | |
---|---|---|---|
Constant (System.UITypes) | Constant (FMX.Consts) | String | |
|
|
||
|
|
|
HardwareBack |
|
|
|
Break |
|
|
|
Clear |
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
Line feed |
|
||
|
|
|
Application |
OEM 102 |
|
|
OEM \ |
OEM-specific Clear key |
|
||
OEM-specific Ico 00 |
|
||
OEM-specific Ico Clear |
|
||
OEM-specific Ico Help |
|
||
|
|
||
Packet |
|
||
Paragraph |
|
|
Paragraph |
|
|
|
Pause |
|
|
||
|
|
||
|
|
||
Reserved |
|
||
|
|||
|
|
||
|
|
||
No key |
|
Representing Shortcuts
The following sections explain how to represent a shortcut as either an instance of TShortCut or a string.
Representing Shortcuts as Instances of TShortCut
To define a shortcut as an instance of System.Classes.TShortCut, join the code of a regular key and the codes of modifier keys using the OR bitwise operator. For example:
Delphi:
Shortcut := vkZ or scShift or scCtrl;
C++:
Shortcut = vkZ | scShift | scCtrl;
Representing Shortcuts Using Strings
To define a shortcut using a string, you can simply concatenate the keys, and place the main key at the end. These are some examples of strings that represent shortcuts:
- ^P (
CTRL
+P
) - Shift+Ctrl+Z (
SHIFT
+CTRL
+Z
)
Specifying Accelerator Keys
On Windows platforms, the Accelerator keys enable the user to access controls using only the keyboard input. For example, by pressing Alt+<accelerator_letter>
key combination. An accelerator key is shown as an underlined letter in the Caption or Text property of your control. To specify an accelerator key in your code, precede an <accelerator_letter>
with an ampersand &
character in the caption or text property of your control. The letter after the ampersand appears underlined in the caption/text on the control. For example, to set the S
character as an accelerator key for a Save
button, type &Save
in the text property. On some controls specified <accelerator_letter>
s appear underlined only when the ALT
key is pressed.
- Note: This feature only works on Windows platforms. When run on other platforms, the ampersand is stripped from the text.
Since an ampersand &
character in a caption/text property is handled as an instruction to underline the next letter, therefore, a single ampersand character is not shown in the caption/text of a corresponding control. To show a single ampersand &
character in a caption/text specify two ampersand &&
characters.
Switching Between Code and String Representation
Given an instance of System.Classes.TShortCut that represents either a key or a shortcut, you may use the following methods to obtain the string representation of that key or shortcut:
Conversely, given the string representation of a key or shortcut, you may use the following methods to obtain an instance of TShortCut that represents that key or shortcut:
Using these functions you can easily set the shortcut of a menu item or some other control at run time using the string representation of the shortcut instead of its code representation, which makes your code more readable:
Delphi:
MenuItem1.ShortCut := TextToShortCut('Cmd+N');
C++:
MenuItem1->ShortCut = TextToShortCut("Cmd+N");