pub enum VirtualKey {
Show 154 variants
Back,
Backspace,
Tab,
Clear,
Return,
Shift,
Control,
Menu,
Pause,
Capital,
Escape,
Space,
Prior,
Next,
End,
Home,
Left,
Up,
Right,
Down,
Select,
Print,
Execute,
Snapshot,
Insert,
Delete,
Help,
LWin,
RWin,
Apps,
Sleep,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
NumpadMultiply,
NumpadAdd,
Separator,
NumpadSubtract,
NumpadDecimal,
NumpadDivide,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
F21,
F22,
F23,
F24,
Numlock,
Scroll,
LShift,
RShift,
LControl,
RControl,
LMenu,
RMenu,
BrowserBack,
BrowserForward,
BrowserRefresh,
BrowserStop,
BrowserSearch,
BrowserFavorites,
BrowserHome,
VolumeMute,
VolumeDown,
VolumeUp,
MediaNextTrack,
MediaPrevTrack,
MediaStop,
MediaPlayPause,
LaunchMail,
LaunchMediaSelect,
LaunchApp1,
LaunchApp2,
Semicolon,
Plus,
Comma,
Minus,
Period,
Slash,
Backquote,
BracketLeft,
Backslash,
BracketRight,
Quote,
Oem8,
Oem102,
Attn,
Crsel,
Exsel,
Play,
Zoom,
Pa1,
OemClear,
Vk0,
Vk1,
Vk2,
Vk3,
Vk4,
Vk5,
Vk6,
Vk7,
Vk8,
Vk9,
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,
CustomKeyCode(u16),
}Expand description
Virtual Key Code wrapper. The codes and variants follow the virtual key codes.
Not supported as enum variants are the mouse buttons, IME keys, VK_PACKET and VK_NONAME.
The letter keys (A to Z) are added as additionall variants, as well as the number keys
(0 to 9) which are available as Vk0 to Vk9.
A VirtualKey can be created for any arbitrary keycode by using the CustomKeyCode variant.
See: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
§Note
Matching against a VirtualKey can be problematic since all of the variants can also be represented
using the CustomKeyCode variant. If a reliable check for a VirtualKey is needed, the keycode
from the VirtualKey::to_vk_code function should be used to get the unique keycode.
Variants§
Back
Backspace key
Backspace
Backspace key
Tab
Tab key
Clear
CLEAR key
Return
ENTER key
Shift
Shift key
Control
CTRL key
Menu
ALT key
Pause
PAUSE
Capital
CAPS LOCK key
Escape
ESC key
Space
SPACEBAR
Prior
PAGE UP key
Next
PAGE DOWN key
End
END key
Home
HOME key
Left
LEFT ARROW key
Up
UP ARROW key
Right
RIGHT ARROW key
Down
DOWN ARROW key
Select
SELECT key
PRINT key
Execute
EXECUTE key
Snapshot
PRINT SCREEN key
Insert
INS key
Delete
DEL key
Help
HELP key
LWin
Left Windows key (Natural keyboard)
RWin
Right Windows key (Natural keyboard)
Apps
Applications key (Natural keyboard)
Sleep
Computer Sleep key
Numpad0
Numeric keypad 0 key
Numpad1
Numeric keypad 1 key
Numpad2
Numeric keypad 2 key
Numpad3
Numeric keypad 3 key
Numpad4
Numeric keypad 4 key
Numpad5
Numeric keypad 5 key
Numpad6
Numeric keypad 6 key
Numpad7
Numeric keypad 7 key
Numpad8
Numeric keypad 8 key
Numpad9
Numeric keypad 9 key
NumpadMultiply
Multiply key
NumpadAdd
Add key
Separator
Separator key
NumpadSubtract
Subtract key
NumpadDecimal
Decimal key
NumpadDivide
Divide key
F1
F1 key
F2
F2 key
F3
F3 key
F4
F4 key
F5
F5 key
F6
F6 key
F7
F7 key
F8
F8 key
F9
F9 key
F10
F10 key
F11
F11 key
F12
F12 key
F13
F13 key
F14
F14 key
F15
F15 key
F16
F16 key
F17
F17 key
F18
F18 key
F19
F19 key
F20
F20 key
F21
F21 key
F22
F22 key
F23
F23 key
F24
F24 key
Numlock
NUM LOCK key
Scroll
SCROLL LOCK key
LShift
Left SHIFT key
RShift
Right SHIFT key
LControl
Left CONTROL key
RControl
Right CONTROL key
LMenu
Left ALT key
RMenu
Right ALT key
BrowserBack
Browser Back key
BrowserForward
Browser Forward key
BrowserRefresh
Browser Refresh key
BrowserStop
Browser Stop key
BrowserSearch
Browser Search key
BrowserFavorites
Browser Favorites key
BrowserHome
Browser Start and Home key
VolumeMute
Volume Mute key
VolumeDown
Volume Down key
VolumeUp
Volume Up key
MediaNextTrack
Next Track key
MediaPrevTrack
Previous Track key
MediaStop
Stop Media key
MediaPlayPause
Play/Pause Media key
LaunchMail
Start Mail key
LaunchMediaSelect
Select Media key
LaunchApp1
Start Application 1 key
LaunchApp2
Start Application 2 key
Semicolon
Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard,
the ;: key
Plus
For any country/region, the + key
Comma
For any country/region, the , key
Minus
For any country/region, the - key
Period
For any country/region, the . key
Slash
Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard,
the /? key
Backquote
Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard,
the ~ key
BracketLeft
Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard,
the [{ key
Backslash
Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard,
the \| key
BracketRight
Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard,
the ]} key
Quote
Used for miscellaneous characters; it can vary by keyboard. For the US standard keyboard,
the "' key
Oem8
Used for miscellaneous characters; it can vary by keyboard.
Oem102
The <> keys on the US standard keyboard, or the \\| key on the non-US 102-key keyboard
Attn
Attn key
Crsel
CrSel key
Exsel
ExSel key
Play
Play key
Zoom
Zoom key
Pa1
PA1 key
OemClear
Clear key
Vk0
0 key
Vk1
1 key
Vk2
2 key
Vk3
3 key
Vk4
4 key
Vk5
5 key
Vk6
6 key
Vk7
7 key
Vk8
8 key
Vk9
9 key
A
A key
B
B key
C
C key
D
D key
E
E key
F
F key
G
G key
H
H key
I
I key
J
J key
K
K key
L
L key
M
M key
N
N key
O
O key
P
P key
Q
Q key
R
R key
S
S key
T
T key
U
U key
V
V key
W
W key
X
X key
Y
Y key
Z
Z key
CustomKeyCode(u16)
Virtual key specified by the actual keycode. This can be used to create a VirtualKey for keys that are not covered by the other enum variants.
See: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
Implementations§
Source§impl VirtualKey
impl VirtualKey
Sourcepub const fn from_char(ch: char) -> Result<Self, HotkeyError>
pub const fn from_char(ch: char) -> Result<Self, HotkeyError>
Try to create a VirtualKey from a char. This only works for the simple number and letter keys (‘A’ to ‘Z’ and ‘0’ to ‘9’). Letters can be upper or lower case
Sourcepub const fn to_vk_code(&self) -> u16
pub const fn to_vk_code(&self) -> u16
Get the actual windows virtual keycode for the VirtualKey for usage with winapi functions
Sourcepub fn from_keyname(val: &str) -> Result<Self, HotkeyError>
pub fn from_keyname(val: &str) -> Result<Self, HotkeyError>
Take in a string and try to guess what Virtual Key (VK) it is meant to represent. Returns the VK code as u16 on success (a key representation was recognized).
- For single character strings the ASCII code is used as VK, this is used to represent alphanumeric keys
- Many of the most common VKs are represented by their constant name. For example VK_SPACE => spacebar key
- Any other key can be represented by directly specifying the VK keycode value in 2 digit hex representation. For example 0x08 == VK_TAB (Tab key)
See https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
Trait Implementations§
Source§impl Clone for VirtualKey
impl Clone for VirtualKey
Source§fn clone(&self) -> VirtualKey
fn clone(&self) -> VirtualKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more