Skip to main content

PhysicalKey

Enum PhysicalKey 

Source
#[repr(C)]
pub enum PhysicalKey {
Show 127 variants Unidentified = 0, KeyA = 1, KeyB = 2, KeyC = 3, KeyD = 4, KeyE = 5, KeyF = 6, KeyG = 7, KeyH = 8, KeyI = 9, KeyJ = 10, KeyK = 11, KeyL = 12, KeyM = 13, KeyN = 14, KeyO = 15, KeyP = 16, KeyQ = 17, KeyR = 18, KeyS = 19, KeyT = 20, KeyU = 21, KeyV = 22, KeyW = 23, KeyX = 24, KeyY = 25, KeyZ = 26, Digit0 = 27, Digit1 = 28, Digit2 = 29, Digit3 = 30, Digit4 = 31, Digit5 = 32, Digit6 = 33, Digit7 = 34, Digit8 = 35, Digit9 = 36, Backquote = 37, Minus = 38, Equal = 39, BracketLeft = 40, BracketRight = 41, Backslash = 42, Semicolon = 43, Quote = 44, Comma = 45, Period = 46, Slash = 47, Enter = 48, Tab = 49, Space = 50, Backspace = 51, Escape = 52, CapsLock = 53, ShiftLeft = 54, ShiftRight = 55, ControlLeft = 56, ControlRight = 57, AltLeft = 58, AltRight = 59, MetaLeft = 60, MetaRight = 61, ContextMenu = 62, Insert = 63, Delete = 64, Home = 65, End = 66, PageUp = 67, PageDown = 68, ArrowUp = 69, ArrowDown = 70, ArrowLeft = 71, ArrowRight = 72, F1 = 73, F2 = 74, F3 = 75, F4 = 76, F5 = 77, F6 = 78, F7 = 79, F8 = 80, F9 = 81, F10 = 82, F11 = 83, F12 = 84, F13 = 85, F14 = 86, F15 = 87, F16 = 88, F17 = 89, F18 = 90, F19 = 91, F20 = 92, F21 = 93, F22 = 94, F23 = 95, F24 = 96, PrintScreen = 97, ScrollLock = 98, Pause = 99, NumLock = 100, NumpadDivide = 101, NumpadMultiply = 102, NumpadSubtract = 103, NumpadAdd = 104, NumpadEnter = 105, NumpadDecimal = 106, NumpadComma = 107, NumpadEqual = 108, Numpad0 = 109, Numpad1 = 110, Numpad2 = 111, Numpad3 = 112, Numpad4 = 113, Numpad5 = 114, Numpad6 = 115, Numpad7 = 116, Numpad8 = 117, Numpad9 = 118, IntlBackslash = 119, IntlRo = 120, IntlYen = 121, Lang1 = 122, Lang2 = 123, Convert = 124, NonConvert = 125, KanaMode = 126,
}
Expand description

A key identified by its PHYSICAL POSITION, independent of layout.

The companion to VirtualKeyCode, which is the LOGICAL key — what the user’s layout says that position produces. Every modern stack splits these because they answer different questions: KeyboardEvent.code vs .key on the web, PhysicalKey vs Key in winit.

ScanCode already carried the physical key as a raw u32, but a raw scancode is platform-specific and unnameable — an app cannot write if scancode == 17 and mean anything portable. This is the same information in a form that can be matched on.

Names follow the W3C UI Events code values, which name each position by what it produces on US ANSI. KeyW is “the key where W sits on a US board” — on AZERTY the user sees Z there, and a game binding “forward” wants that position regardless.

Variants§

§

Unidentified = 0

The platform reported a position this enum does not name.

§

KeyA = 1

§

KeyB = 2

§

KeyC = 3

§

KeyD = 4

§

KeyE = 5

§

KeyF = 6

§

KeyG = 7

§

KeyH = 8

§

KeyI = 9

§

KeyJ = 10

§

KeyK = 11

§

KeyL = 12

§

KeyM = 13

§

KeyN = 14

§

KeyO = 15

§

KeyP = 16

§

KeyQ = 17

§

KeyR = 18

§

KeyS = 19

§

KeyT = 20

§

KeyU = 21

§

KeyV = 22

§

KeyW = 23

§

KeyX = 24

§

KeyY = 25

§

KeyZ = 26

§

Digit0 = 27

§

Digit1 = 28

§

Digit2 = 29

§

Digit3 = 30

§

Digit4 = 31

§

Digit5 = 32

§

Digit6 = 33

§

Digit7 = 34

§

Digit8 = 35

§

Digit9 = 36

§

Backquote = 37

§

Minus = 38

§

Equal = 39

§

BracketLeft = 40

§

BracketRight = 41

§

Backslash = 42

§

Semicolon = 43

§

Quote = 44

§

Comma = 45

§

Period = 46

§

Slash = 47

§

Enter = 48

§

Tab = 49

§

Space = 50

§

Backspace = 51

§

Escape = 52

§

CapsLock = 53

§

ShiftLeft = 54

§

ShiftRight = 55

§

ControlLeft = 56

§

ControlRight = 57

§

AltLeft = 58

§

AltRight = 59

§

MetaLeft = 60

§

MetaRight = 61

§

ContextMenu = 62

§

Insert = 63

§

Delete = 64

§

Home = 65

§

End = 66

§

PageUp = 67

§

PageDown = 68

§

ArrowUp = 69

§

ArrowDown = 70

§

ArrowLeft = 71

§

ArrowRight = 72

§

F1 = 73

§

F2 = 74

§

F3 = 75

§

F4 = 76

§

F5 = 77

§

F6 = 78

§

F7 = 79

§

F8 = 80

§

F9 = 81

§

F10 = 82

§

F11 = 83

§

F12 = 84

§

F13 = 85

§

F14 = 86

§

F15 = 87

§

F16 = 88

§

F17 = 89

§

F18 = 90

§

F19 = 91

§

F20 = 92

§

F21 = 93

§

F22 = 94

§

F23 = 95

§

F24 = 96

§

PrintScreen = 97

§

ScrollLock = 98

§

Pause = 99

§

NumLock = 100

§

NumpadDivide = 101

§

NumpadMultiply = 102

§

NumpadSubtract = 103

§

NumpadAdd = 104

§

NumpadEnter = 105

§

NumpadDecimal = 106

§

NumpadComma = 107

§

NumpadEqual = 108

§

Numpad0 = 109

§

Numpad1 = 110

§

Numpad2 = 111

§

Numpad3 = 112

§

Numpad4 = 113

§

Numpad5 = 114

§

Numpad6 = 115

§

Numpad7 = 116

§

Numpad8 = 117

§

Numpad9 = 118

§

IntlBackslash = 119

§

IntlRo = 120

§

IntlYen = 121

§

Lang1 = 122

§

Lang2 = 123

§

Convert = 124

§

NonConvert = 125

§

KanaMode = 126

Implementations§

Source§

impl PhysicalKey

Source

pub const fn from_evdev(code: u32) -> Self

Linux evdev keycode -> position.

Used directly by Wayland and Android. X11 callers must pass keycode - 8; see Self::from_x11_keycode.

Source

pub const fn from_x11_keycode(keycode: u32) -> Self

X11 keycode -> position.

XKB keycodes are evdev + 8 by protocol, so this is the evdev table with the offset removed. A keycode below 8 cannot be an evdev key and is reported as unidentified rather than wrapping into a wrong one.

Source

pub const fn from_windows_scancode(scancode: u32, extended: bool) -> Self

PS/2 set-1 scancode -> position, as WM_KEYDOWN reports it.

extended is lParam bit 24 (the E0 prefix). It is not optional detail: without it Enter and NumpadEnter, ControlLeft and ControlRight, and the whole arrow cluster versus the numpad are the SAME scancode.

Source

pub const fn from_macos_keycode(keycode: u16) -> Self

Carbon virtual keycode (NSEvent.keyCode) -> position.

Cross-checked entry by entry against macos_keycode_to_virtual_key, the table this codebase already trusts for the LOGICAL key; the two agree on every code both name.

Trait Implementations§

Source§

impl Clone for PhysicalKey

Source§

fn clone(&self) -> PhysicalKey

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for PhysicalKey

Source§

impl Debug for PhysicalKey

Source§

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

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

impl Eq for PhysicalKey

Source§

impl Hash for PhysicalKey

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 Ord for PhysicalKey

Source§

fn cmp(&self, other: &PhysicalKey) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for PhysicalKey

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for PhysicalKey

Source§

fn partial_cmp(&self, other: &PhysicalKey) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for PhysicalKey

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> GetHash for T
where T: Hash,

Source§

fn get_hash(&self) -> u64

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.