tao::event

Struct KeyEvent

Source
pub struct KeyEvent {
    pub physical_key: KeyCode,
    pub logical_key: Key<'static>,
    pub text: Option<&'static str>,
    pub location: KeyLocation,
    pub state: ElementState,
    pub repeat: bool,
    /* private fields */
}
Expand description

Describes a keyboard input targeting a window.

Fields§

§physical_key: KeyCode

Represents the position of a key independent of the currently active layout.

It also uniquely identifies the physical key (i.e. it’s mostly synonymous with a scancode). The most prevalent use case for this is games. For example the default keys for the player to move around might be the W, A, S, and D keys on a US layout. The position of these keys is more important than their label, so they should map to Z, Q, S, and D on an “AZERTY” layout. (This value is KeyCode::KeyW for the Z key on an AZERTY layout.)

Note that Fn and FnLock key events are not guaranteed to be emitted by tao. These keys are usually handled at the hardware or OS level.

§logical_key: Key<'static>

This value is affected by all modifiers except Ctrl.

This has two use cases:

  • Allows querying whether the current input is a Dead key.
  • Allows handling key-bindings on platforms which don’t support key_without_modifiers.

§Platform-specific

  • Web: Dead keys might be reported as the real key instead of Dead depending on the browser/OS.
§text: Option<&'static str>

Contains the text produced by this keypress.

In most cases this is identical to the content of the Character variant of logical_key. However, on Windows when a dead key was pressed earlier but cannot be combined with the character from this keypress, the produced text will consist of two characters: the dead-key-character followed by the character resulting from this keypress.

An additional difference from logical_key is that this field stores the text representation of any key that has such a representation. For example when logical_key is Key::Enter, this field is Some("\r").

This is None if the current keypress cannot be interpreted as text.

See also: text_with_all_modifiers()

§location: KeyLocation§state: ElementState§repeat: bool

Implementations§

Source§

impl KeyEvent

Source

pub fn text_with_all_modifiers(&self) -> Option<&str>

Identical to KeyEvent::text but this is affected by Ctrl.

For example, pressing Ctrl+a produces Some("\x01").

Source

pub fn key_without_modifiers(&self) -> Key<'static>

This value ignores all modifiers including, but not limited to Shift, Caps Lock, and Ctrl. In most cases this means that the unicode character in the resulting string is lowercase.

This is useful for key-bindings / shortcut key combinations.

In case logical_key reports Dead, this will still report the key as Character according to the current keyboard layout. This value cannot be Dead.

Trait Implementations§

Source§

impl Clone for KeyEvent

Source§

fn clone(&self) -> KeyEvent

Returns a copy 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 KeyEvent

Source§

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

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

impl Hash for KeyEvent

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 KeyEvent

Source§

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

Source§

impl StructuralPartialEq for KeyEvent

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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, 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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T