Skip to main content

WinitKeyExt

Trait WinitKeyExt 

Source
pub trait WinitKeyExt: Sealed {
    // Required method
    fn to_key(&self) -> Option<Key>;
}
Expand description

Convert a winit key type to a kbd Key.

Returns None for keys that have no kbd equivalent (e.g., Unidentified, keys beyond F24, TV remote keys).

This trait is sealed and cannot be implemented outside this crate.

Required Methods§

Source

fn to_key(&self) -> Option<Key>

Convert this winit key to a kbd Key, or None if unmappable.

§Examples
use kbd::prelude::*;
use kbd_winit::WinitKeyExt;
use winit::keyboard::{KeyCode, PhysicalKey};

assert_eq!(KeyCode::KeyA.to_key(), Some(Key::A));
assert_eq!(PhysicalKey::Code(KeyCode::Enter).to_key(), Some(Key::ENTER));
assert_eq!(KeyCode::SuperLeft.to_key(), Some(Key::META_LEFT));

Implementations on Foreign Types§

Source§

impl WinitKeyExt for KeyCode

Source§

fn to_key(&self) -> Option<Key>

Source§

impl WinitKeyExt for PhysicalKey

Source§

fn to_key(&self) -> Option<Key>

Implementors§