basalt 0.21.0

A window/ui framework built upon vulkan.
Documentation
use winit::event::KeyEvent;
use winit::keyboard::{Key, KeyCode, NamedKey, NativeKeyCode, PhysicalKey};

use crate::input::Qwerty;

pub fn event_to_qwerty(event: &KeyEvent) -> Option<Qwerty> {
    let by_logical = match event.logical_key {
        Key::Named(named_key) => {
            match named_key {
                NamedKey::AudioVolumeMute => Some(Qwerty::TrackMute),
                NamedKey::AudioVolumeDown => Some(Qwerty::TrackVolDown),
                NamedKey::AudioVolumeUp => Some(Qwerty::TrackVolUp),
                NamedKey::MediaPlayPause => Some(Qwerty::TrackPlayPause),
                NamedKey::MediaLast => Some(Qwerty::TrackBack),
                NamedKey::MediaSkipForward => Some(Qwerty::TrackNext),
                _ => None,
            }
        },
        _ => None,
    };

    if let Some(qwerty) = by_logical {
        return Some(qwerty);
    }

    match event.physical_key {
        PhysicalKey::Code(code) => {
            match code {
                KeyCode::Escape => Some(Qwerty::Esc),
                KeyCode::F1 => Some(Qwerty::F1),
                KeyCode::F2 => Some(Qwerty::F2),
                KeyCode::F3 => Some(Qwerty::F3),
                KeyCode::F4 => Some(Qwerty::F4),
                KeyCode::F5 => Some(Qwerty::F5),
                KeyCode::F6 => Some(Qwerty::F6),
                KeyCode::F7 => Some(Qwerty::F7),
                KeyCode::F8 => Some(Qwerty::F8),
                KeyCode::F9 => Some(Qwerty::F9),
                KeyCode::F10 => Some(Qwerty::F10),
                KeyCode::F11 => Some(Qwerty::F11),
                KeyCode::F12 => Some(Qwerty::F12),
                KeyCode::Backquote => Some(Qwerty::Tilda),
                KeyCode::Digit1 => Some(Qwerty::One),
                KeyCode::Digit2 => Some(Qwerty::Two),
                KeyCode::Digit3 => Some(Qwerty::Three),
                KeyCode::Digit4 => Some(Qwerty::Four),
                KeyCode::Digit5 => Some(Qwerty::Five),
                KeyCode::Digit6 => Some(Qwerty::Six),
                KeyCode::Digit7 => Some(Qwerty::Seven),
                KeyCode::Digit8 => Some(Qwerty::Eight),
                KeyCode::Digit9 => Some(Qwerty::Nine),
                KeyCode::Digit0 => Some(Qwerty::Zero),
                KeyCode::Minus => Some(Qwerty::Dash),
                KeyCode::Equal => Some(Qwerty::Equal),
                KeyCode::Backspace => Some(Qwerty::Backspace),
                KeyCode::Tab => Some(Qwerty::Tab),
                KeyCode::KeyQ => Some(Qwerty::Q),
                KeyCode::KeyW => Some(Qwerty::W),
                KeyCode::KeyE => Some(Qwerty::E),
                KeyCode::KeyR => Some(Qwerty::R),
                KeyCode::KeyT => Some(Qwerty::T),
                KeyCode::KeyY => Some(Qwerty::Y),
                KeyCode::KeyU => Some(Qwerty::U),
                KeyCode::KeyI => Some(Qwerty::I),
                KeyCode::KeyO => Some(Qwerty::O),
                KeyCode::KeyP => Some(Qwerty::P),
                KeyCode::BracketLeft => Some(Qwerty::LSqBracket),
                KeyCode::BracketRight => Some(Qwerty::RSqBracket),
                KeyCode::Backslash => Some(Qwerty::Backslash),
                KeyCode::CapsLock => Some(Qwerty::Caps),
                KeyCode::KeyA => Some(Qwerty::A),
                KeyCode::KeyS => Some(Qwerty::S),
                KeyCode::KeyD => Some(Qwerty::D),
                KeyCode::KeyF => Some(Qwerty::F),
                KeyCode::KeyG => Some(Qwerty::G),
                KeyCode::KeyH => Some(Qwerty::H),
                KeyCode::KeyJ => Some(Qwerty::J),
                KeyCode::KeyK => Some(Qwerty::K),
                KeyCode::KeyL => Some(Qwerty::L),
                KeyCode::Semicolon => Some(Qwerty::SemiColon),
                KeyCode::Quote => Some(Qwerty::Parenthesis),
                KeyCode::Enter => Some(Qwerty::Enter),
                KeyCode::ShiftLeft => Some(Qwerty::LShift),
                KeyCode::KeyZ => Some(Qwerty::Z),
                KeyCode::KeyX => Some(Qwerty::X),
                KeyCode::KeyC => Some(Qwerty::C),
                KeyCode::KeyV => Some(Qwerty::V),
                KeyCode::KeyB => Some(Qwerty::B),
                KeyCode::KeyN => Some(Qwerty::N),
                KeyCode::KeyM => Some(Qwerty::M),
                KeyCode::Comma => Some(Qwerty::Comma),
                KeyCode::Period => Some(Qwerty::Period),
                KeyCode::Slash => Some(Qwerty::Slash),
                KeyCode::ShiftRight => Some(Qwerty::RShift),
                KeyCode::ControlLeft => Some(Qwerty::LCtrl),
                KeyCode::SuperLeft => Some(Qwerty::LSuper),
                KeyCode::AltLeft => Some(Qwerty::LAlt),
                KeyCode::Space => Some(Qwerty::Space),
                KeyCode::AltRight => Some(Qwerty::RAlt),
                KeyCode::SuperRight => Some(Qwerty::RSuper),
                KeyCode::ControlRight => Some(Qwerty::RCtrl),
                KeyCode::PrintScreen => Some(Qwerty::PrintScreen),
                KeyCode::ScrollLock => Some(Qwerty::ScrollLock),
                KeyCode::Pause => Some(Qwerty::Pause),
                KeyCode::Insert => Some(Qwerty::Insert),
                KeyCode::Home => Some(Qwerty::Home),
                KeyCode::PageUp => Some(Qwerty::PageUp),
                KeyCode::Delete => Some(Qwerty::Delete),
                KeyCode::End => Some(Qwerty::End),
                KeyCode::PageDown => Some(Qwerty::PageDown),
                KeyCode::ArrowUp => Some(Qwerty::ArrowUp),
                KeyCode::ArrowDown => Some(Qwerty::ArrowDown),
                KeyCode::ArrowLeft => Some(Qwerty::ArrowLeft),
                KeyCode::ArrowRight => Some(Qwerty::ArrowRight),
                _ => None,
            }
        },
        PhysicalKey::Unidentified(NativeKeyCode::Windows(0xE11D)) => Some(Qwerty::Pause),
        _ => None,
    }
}