pub enum Key<C = SmolStr> {
Named(Named),
Character(C),
Unidentified,
}Expand description
A key on the keyboard.
This is mostly the Key type found in winit.
Variants§
Named(Named)
A key with an established name.
Character(C)
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
An unidentified key.
Implementations§
Source§impl Key
impl Key
Sourcepub fn as_ref(&self) -> Key<&str>
pub fn as_ref(&self) -> Key<&str>
Convert Key::Character(SmolStr) to Key::Character(&str) so you can more easily match on
Key. All other variants remain unchanged.
Sourcepub fn to_latin(&self, physical_key: Physical) -> Option<char>
pub fn to_latin(&self, physical_key: Physical) -> Option<char>
Tries to convert this logical Key into its latin character, using the
Physical key provided for translation if it isn’t already in latin.
Returns None if no latin variant could be found.
use iced_core::keyboard::key::{Key, Named, Physical, Code};
// Latin c
assert_eq!(
Key::Character("c".into()).to_latin(Physical::Code(Code::KeyC)),
Some('c'),
);
// Cyrillic с
assert_eq!(
Key::Character("с".into()).to_latin(Physical::Code(Code::KeyC)),
Some('c'),
);
// Arrow Left
assert_eq!(
Key::Named(Named::ArrowLeft).to_latin(Physical::Code(Code::ArrowLeft)),
None,
);Trait Implementations§
Source§impl<C: Ord> Ord for Key<C>
impl<C: Ord> Ord for Key<C>
Source§impl<C: PartialOrd> PartialOrd for Key<C>
impl<C: PartialOrd> PartialOrd for Key<C>
impl<C: Eq> Eq for Key<C>
impl<C> StructuralPartialEq for Key<C>
Auto Trait Implementations§
impl<C> Freeze for Key<C>where
C: Freeze,
impl<C> RefUnwindSafe for Key<C>where
C: RefUnwindSafe,
impl<C> Send for Key<C>where
C: Send,
impl<C> Sync for Key<C>where
C: Sync,
impl<C> Unpin for Key<C>where
C: Unpin,
impl<C> UnwindSafe for Key<C>where
C: 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