Skip to main content

KeyCode

Enum KeyCode 

Source
#[non_exhaustive]
pub enum KeyCode {
Show 107 variants KeyA, KeyB, KeyC, KeyD, KeyE, KeyF, KeyG, KeyH, KeyI, KeyJ, KeyK, KeyL, KeyM, KeyN, KeyO, KeyP, KeyQ, KeyR, KeyS, KeyT, KeyU, KeyV, KeyW, KeyX, KeyY, KeyZ, Digit0, Digit1, Digit2, Digit3, Digit4, Digit5, Digit6, Digit7, Digit8, Digit9, Backquote, Minus, Equal, BracketLeft, BracketRight, Backslash, Semicolon, Quote, Comma, Period, Slash, IntlBackslash, IntlRo, IntlYen, Escape, Tab, CapsLock, Space, Backspace, Enter, Delete, Insert, ShiftLeft, ShiftRight, ControlLeft, ControlRight, AltLeft, AltRight, SuperLeft, SuperRight, ContextMenu, Home, End, PageUp, PageDown, ArrowUp, ArrowDown, ArrowLeft, ArrowRight, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PrintScreen, ScrollLock, Pause, NumLock, Numpad0, Numpad1, Numpad2, Numpad3, Numpad4, Numpad5, Numpad6, Numpad7, Numpad8, Numpad9, NumpadDivide, NumpadMultiply, NumpadSubtract, NumpadAdd, NumpadEnter, NumpadDecimal,
}
Expand description

A key identified by physical position, independent of keyboard layout.

Variant names follow the W3C UI Events code values, which name positions after the US-QWERTY legends: KeyCode::KeyW is the key where W is on a US keyboard, which on AZERTY is the key labelled Z. That is precisely the property gameplay bindings want — WASD stays a square under the left hand everywhere — and precisely the property a rebind menu must not display, which is what Keysym is for.

§Non-exhaustive on purpose

Unlike SurfaceTarget, which is exhaustive so that a new platform breaks every backend loudly, this enum is #[non_exhaustive]: consumers match a handful of keys and fall through on the rest, so adding a key must not be a breaking change. A key nobody named is a key nobody bound, which degrades to “the binding does not fire” — not to a wrong action.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

KeyA

The KeyA key.

§

KeyB

The KeyB key.

§

KeyC

The KeyC key.

§

KeyD

The KeyD key.

§

KeyE

The KeyE key.

§

KeyF

The KeyF key.

§

KeyG

The KeyG key.

§

KeyH

The KeyH key.

§

KeyI

The KeyI key.

§

KeyJ

The KeyJ key.

§

KeyK

The KeyK key.

§

KeyL

The KeyL key.

§

KeyM

The KeyM key.

§

KeyN

The KeyN key.

§

KeyO

The KeyO key.

§

KeyP

The KeyP key.

§

KeyQ

The KeyQ key.

§

KeyR

The KeyR key.

§

KeyS

The KeyS key.

§

KeyT

The KeyT key.

§

KeyU

The KeyU key.

§

KeyV

The KeyV key.

§

KeyW

The KeyW key.

§

KeyX

The KeyX key.

§

KeyY

The KeyY key.

§

KeyZ

The KeyZ key.

§

Digit0

The Digit0 key.

§

Digit1

The Digit1 key.

§

Digit2

The Digit2 key.

§

Digit3

The Digit3 key.

§

Digit4

The Digit4 key.

§

Digit5

The Digit5 key.

§

Digit6

The Digit6 key.

§

Digit7

The Digit7 key.

§

Digit8

The Digit8 key.

§

Digit9

The Digit9 key.

§

Backquote

The Backquote key.

§

Minus

The Minus key.

§

Equal

The Equal key.

§

BracketLeft

The BracketLeft key.

§

BracketRight

The BracketRight key.

§

Backslash

The Backslash key.

§

Semicolon

The Semicolon key.

§

Quote

The Quote key.

§

Comma

The Comma key.

§

Period

The Period key.

§

Slash

The Slash key.

§

IntlBackslash

The IntlBackslash key.

§

IntlRo

The IntlRo key.

§

IntlYen

The IntlYen key.

§

Escape

The Escape key.

§

Tab

The Tab key.

§

CapsLock

The CapsLock key.

§

Space

The Space key.

§

Backspace

The Backspace key.

§

Enter

The Enter key.

§

Delete

The Delete key.

§

Insert

The Insert key.

§

ShiftLeft

The ShiftLeft key.

§

ShiftRight

The ShiftRight key.

§

ControlLeft

The ControlLeft key.

§

ControlRight

The ControlRight key.

§

AltLeft

The AltLeft key.

§

AltRight

The AltRight key.

§

SuperLeft

The SuperLeft key.

§

SuperRight

The SuperRight key.

§

ContextMenu

The ContextMenu key.

§

Home

The Home key.

§

End

The End key.

§

PageUp

The PageUp key.

§

PageDown

The PageDown key.

§

ArrowUp

The ArrowUp key.

§

ArrowDown

The ArrowDown key.

§

ArrowLeft

The ArrowLeft key.

§

ArrowRight

The ArrowRight key.

§

F1

The F1 key.

§

F2

The F2 key.

§

F3

The F3 key.

§

F4

The F4 key.

§

F5

The F5 key.

§

F6

The F6 key.

§

F7

The F7 key.

§

F8

The F8 key.

§

F9

The F9 key.

§

F10

The F10 key.

§

F11

The F11 key.

§

F12

The F12 key.

§

PrintScreen

The PrintScreen key.

§

ScrollLock

The ScrollLock key.

§

Pause

The Pause key.

§

NumLock

The NumLock key.

§

Numpad0

The Numpad0 key.

§

Numpad1

The Numpad1 key.

§

Numpad2

The Numpad2 key.

§

Numpad3

The Numpad3 key.

§

Numpad4

The Numpad4 key.

§

Numpad5

The Numpad5 key.

§

Numpad6

The Numpad6 key.

§

Numpad7

The Numpad7 key.

§

Numpad8

The Numpad8 key.

§

Numpad9

The Numpad9 key.

§

NumpadDivide

The NumpadDivide key.

§

NumpadMultiply

The NumpadMultiply key.

§

NumpadSubtract

The NumpadSubtract key.

§

NumpadAdd

The NumpadAdd key.

§

NumpadEnter

The NumpadEnter key.

§

NumpadDecimal

The NumpadDecimal key.

Implementations§

Source§

impl KeyCode

Source

pub const ALL: &'static [KeyCode]

Every key this engine has a name for, in declaration order.

Used by the rebind UI to enumerate choices and by tests to prove the name table round-trips.

Source

pub const fn as_str(self) -> &'static str

The stable name of this key, as written in binding assets and profiles.

Stable across releases: it is a serialization format, not a display string. A rebind menu shows the keysym, not this.

Source

pub fn from_name(name: &str) -> Option<KeyCode>

Parses a name produced by KeyCode::as_str.

Not a FromStr impl: the only possible failure is “no such key”, and an error type carrying that one fact would be ceremony. Bindings for unknown names are kept as Scancode by the profile loader rather than dropped.

Trait Implementations§

Source§

impl Clone for KeyCode

Source§

fn clone(&self) -> KeyCode

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 KeyCode

Source§

impl Debug for KeyCode

Source§

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

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

impl Display for KeyCode

Source§

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

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

impl Eq for KeyCode

Source§

impl Hash for KeyCode

Source§

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

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 KeyCode

Source§

fn cmp(&self, other: &KeyCode) -> 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 KeyCode

Source§

fn eq(&self, other: &KeyCode) -> 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 KeyCode

Source§

fn partial_cmp(&self, other: &KeyCode) -> 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 KeyCode

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 = !

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.