pub enum Key<Str = SmolStr> {
Named(NamedKey),
Character(Str),
Unidentified(NativeKey),
Dead(Option<char>),
}
Expand description
Key represents the meaning of a keypress.
This is a superset of the UI Events Specification’s KeyboardEvent.key
with
additions:
- All simple variants are wrapped under the
Named
variant - The
Unidentified
variant here, can still identifiy a key through it’sNativeKeyCode
. - The
Dead
variant here, can specify the character which is inserted when pressing the dead-key twice.
Variants§
Named(NamedKey)
A simple (unparameterised) action
Character(Str)
A key string that corresponds to the character typed by the user, taking into account the user’s current locale setting, and any system-level keyboard mapping overrides that are in effect.
Unidentified(NativeKey)
This variant is used when the key cannot be translated to any other variant.
The native key is provided (if available) in order to allow the user to specify keybindings for keys which are not defined by this API, mainly through some sort of UI.
Dead(Option<char>)
Contains the text representation of the dead-key when available.
Platform-specific
- Web: Always contains
None
Implementations§
source§impl Key
impl Key
sourcepub fn to_text(&self) -> Option<&str>
pub fn to_text(&self) -> Option<&str>
Convert a key to its approximate textual equivalent.
Examples
use winit::keyboard::{NamedKey, Key};
assert_eq!(Key::Character("a".into()).to_text(), Some("a"));
assert_eq!(Key::Named(NamedKey::Enter).to_text(), Some("\r"));
assert_eq!(Key::Named(NamedKey::F20).to_text(), None);
Trait Implementations§
source§impl<Str: Ord> Ord for Key<Str>
impl<Str: Ord> Ord for Key<Str>
source§impl<Str> PartialEq<Key<Str>> for NativeKey
impl<Str> PartialEq<Key<Str>> for NativeKey
source§impl<Str> PartialEq<NamedKey> for Key<Str>
impl<Str> PartialEq<NamedKey> for Key<Str>
source§impl<Str> PartialEq<NativeKey> for Key<Str>
impl<Str> PartialEq<NativeKey> for Key<Str>
source§impl<Str: PartialEq> PartialEq for Key<Str>
impl<Str: PartialEq> PartialEq for Key<Str>
source§impl<Str: PartialOrd> PartialOrd for Key<Str>
impl<Str: PartialOrd> PartialOrd for Key<Str>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<Str: Eq> Eq for Key<Str>
impl<Str> StructuralEq for Key<Str>
impl<Str> StructuralPartialEq for Key<Str>
Auto Trait Implementations§
impl<Str> RefUnwindSafe for Key<Str>where
Str: RefUnwindSafe,
impl<Str> Send for Key<Str>where
Str: Send,
impl<Str> Sync for Key<Str>where
Str: Sync,
impl<Str> Unpin for Key<Str>where
Str: Unpin,
impl<Str> UnwindSafe for Key<Str>where
Str: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.