VirtualKey

Enum VirtualKey 

Source
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

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

Source

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

Source

pub const fn to_vk_code(&self) -> u16

Get the actual windows virtual keycode for the VirtualKey for usage with winapi functions

Source

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

Source§

fn clone(&self) -> VirtualKey

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VirtualKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for VirtualKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ModifiersKey> for VirtualKey

Source§

fn from(mk: ModifiersKey) -> VirtualKey

Converts to this type from the input type.
Source§

impl Hash for VirtualKey

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for VirtualKey

Source§

fn eq(&self, other: &VirtualKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&str> for VirtualKey

Source§

type Error = HotkeyError

The type returned in the event of a conversion error.
Source§

fn try_from(val: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<char> for VirtualKey

Source§

type Error = HotkeyError

The type returned in the event of a conversion error.
Source§

fn try_from(ch: char) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryInto<ModifiersKey> for VirtualKey

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<ModifiersKey, Self::Error>

Performs the conversion.
Source§

impl Copy for VirtualKey

Source§

impl Eq for VirtualKey

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.