nuhxboard 0.3.1

A Linux port of NohBoard
use iced::keyboard::KeyCode;
use rdev::{Button, Key};

pub fn mouse_button_code_convert(rdev_button: Button) -> u32 {
    match rdev_button {
        Button::Left => 0,
        Button::Middle => 2,
        Button::Right => 1,
        Button::Unknown(code) => match code {
            8 | 19 => 3,
            9 | 20 => 4,
            _ => panic!("Unknown mouse button code: {:?}", rdev_button),
        },
    }
}

pub fn keycode_convert(rdev_key: Key) -> u32 {
    match rdev_key {
        Key::Backspace => 8,
        Key::Tab => 9,
        Key::Return => 13,
        Key::Pause => 19,
        Key::CapsLock => 20,
        Key::Escape => 27,
        Key::Space => 32,
        Key::PageUp => 33,
        Key::PageDown => 34,
        Key::End => 35,
        Key::Home => 36,
        Key::LeftArrow => 37,
        Key::UpArrow => 38,
        Key::RightArrow => 39,
        Key::DownArrow => 40,
        Key::PrintScreen => 44,
        Key::Insert => 45,
        Key::Delete => 46,
        Key::Num0 => 48,
        Key::Num1 => 49,
        Key::Num2 => 50,
        Key::Num3 => 51,
        Key::Num4 => 52,
        Key::Num5 => 53,
        Key::Num6 => 54,
        Key::Num7 => 55,
        Key::Num8 => 56,
        Key::Num9 => 57,
        Key::KeyA => 65,
        Key::KeyB => 66,
        Key::KeyC => 67,
        Key::KeyD => 68,
        Key::KeyE => 69,
        Key::KeyF => 70,
        Key::KeyG => 71,
        Key::KeyH => 72,
        Key::KeyI => 73,
        Key::KeyJ => 74,
        Key::KeyK => 75,
        Key::KeyL => 76,
        Key::KeyM => 77,
        Key::KeyN => 78,
        Key::KeyO => 79,
        Key::KeyP => 80,
        Key::KeyQ => 81,
        Key::KeyR => 82,
        Key::KeyS => 83,
        Key::KeyT => 84,
        Key::KeyU => 85,
        Key::KeyV => 86,
        Key::KeyW => 87,
        Key::KeyX => 88,
        Key::KeyY => 89,
        Key::KeyZ => 90,
        Key::Kp0 => 96,
        Key::Kp1 => 97,
        Key::Kp2 => 98,
        Key::Kp3 => 99,
        Key::Kp4 => 100,
        Key::Kp5 => 101,
        Key::Kp6 => 102,
        Key::Kp7 => 103,
        Key::Kp8 => 104,
        Key::Kp9 => 105,
        Key::KpMultiply => 106,
        Key::KpPlus => 107,
        Key::KpMinus => 109,
        Key::KpDelete => 110,
        Key::KpDivide => 111,
        Key::F1 => 112,
        Key::F2 => 113,
        Key::F3 => 114,
        Key::F4 => 115,
        Key::F5 => 116,
        Key::F6 => 117,
        Key::F7 => 118,
        Key::F8 => 119,
        Key::F9 => 120,
        Key::F10 => 121,
        Key::F11 => 122,
        Key::F12 => 123,
        Key::ShiftLeft => 160,
        Key::ShiftRight => 161,
        Key::ControlLeft => 162,
        Key::ControlRight => 163,
        Key::Alt => 164,
        Key::AltGr => 165,
        Key::SemiColon => 186,
        Key::Equal => 187,
        Key::Comma => 188,
        Key::Minus => 189,
        Key::Dot => 190,
        Key::Slash => 191,
        Key::BackQuote => 192,
        Key::LeftBracket => 219,
        Key::BackSlash => 220,
        Key::RightBracket => 221,
        Key::Quote => 222,
        Key::NumLock => 144,
        Key::KpReturn => 1025,
        // Menu
        Key::Unknown(135) => 93,
        _ => panic!("Unknown xinput code: {:?}", rdev_key),
    }
}

pub fn iced_to_rdev(iced_code: iced::keyboard::KeyCode) -> rdev::Key {
    match iced_code {
        KeyCode::Backspace => Key::Backspace,
        KeyCode::Tab => Key::Tab,
        KeyCode::Enter => Key::Return,
        KeyCode::Pause => Key::Pause,
        KeyCode::Escape => Key::Escape,
        KeyCode::Space => Key::Space,
        KeyCode::PageUp => Key::PageUp,
        KeyCode::PageDown => Key::PageDown,
        KeyCode::End => Key::End,
        KeyCode::Home => Key::Home,
        KeyCode::Left => Key::LeftArrow,
        KeyCode::Up => Key::UpArrow,
        KeyCode::Right => Key::RightArrow,
        KeyCode::Down => Key::DownArrow,
        KeyCode::Snapshot => Key::PrintScreen,
        KeyCode::Insert => Key::Insert,
        KeyCode::Delete => Key::Delete,
        KeyCode::Key0 => Key::Num0,
        KeyCode::Key1 => Key::Num1,
        KeyCode::Key2 => Key::Num2,
        KeyCode::Key3 => Key::Num3,
        KeyCode::Key4 => Key::Num4,
        KeyCode::Key5 => Key::Num5,
        KeyCode::Key6 => Key::Num6,
        KeyCode::Key7 => Key::Num7,
        KeyCode::Key8 => Key::Num8,
        KeyCode::Key9 => Key::Num9,
        KeyCode::A => Key::KeyA,
        KeyCode::B => Key::KeyB,
        KeyCode::C => Key::KeyC,
        KeyCode::D => Key::KeyD,
        KeyCode::E => Key::KeyE,
        KeyCode::F => Key::KeyF,
        KeyCode::G => Key::KeyG,
        KeyCode::H => Key::KeyH,
        KeyCode::I => Key::KeyI,
        KeyCode::J => Key::KeyJ,
        KeyCode::K => Key::KeyK,
        KeyCode::L => Key::KeyL,
        KeyCode::M => Key::KeyM,
        KeyCode::N => Key::KeyN,
        KeyCode::O => Key::KeyO,
        KeyCode::P => Key::KeyP,
        KeyCode::Q => Key::KeyQ,
        KeyCode::R => Key::KeyR,
        KeyCode::S => Key::KeyS,
        KeyCode::T => Key::KeyT,
        KeyCode::U => Key::KeyU,
        KeyCode::V => Key::KeyV,
        KeyCode::W => Key::KeyW,
        KeyCode::X => Key::KeyX,
        KeyCode::Y => Key::KeyY,
        KeyCode::Z => Key::KeyZ,
        KeyCode::F1 => Key::F1,
        KeyCode::F2 => Key::F2,
        KeyCode::F3 => Key::F3,
        KeyCode::F4 => Key::F4,
        KeyCode::F5 => Key::F5,
        KeyCode::F6 => Key::F6,
        KeyCode::F7 => Key::F7,
        KeyCode::F8 => Key::F8,
        KeyCode::F9 => Key::F9,
        KeyCode::F10 => Key::F10,
        KeyCode::F11 => Key::F11,
        KeyCode::F12 => Key::F12,
        KeyCode::Numlock => Key::NumLock,
        KeyCode::Numpad0 => Key::Kp0,
        KeyCode::Numpad1 => Key::Kp1,
        KeyCode::Numpad2 => Key::Kp2,
        KeyCode::Numpad3 => Key::Kp3,
        KeyCode::Numpad4 => Key::Kp4,
        KeyCode::Numpad5 => Key::Kp5,
        KeyCode::Numpad6 => Key::Kp6,
        KeyCode::Numpad7 => Key::Kp7,
        KeyCode::Numpad8 => Key::Kp8,
        KeyCode::Numpad9 => Key::Kp9,
        KeyCode::NumpadAdd => Key::KpPlus,
        KeyCode::NumpadSubtract => Key::KpMinus,
        KeyCode::NumpadMultiply => Key::KpMultiply,
        KeyCode::NumpadDivide => Key::KpDivide,
        KeyCode::NumpadEnter => Key::KpReturn,
        KeyCode::LShift => Key::ShiftLeft,
        KeyCode::RShift => Key::ShiftRight,
        KeyCode::LControl => Key::ControlLeft,
        KeyCode::RControl => Key::ControlRight,
        KeyCode::LAlt => Key::Alt,
        KeyCode::RAlt => Key::AltGr,
        KeyCode::Semicolon => Key::SemiColon,
        KeyCode::Equals => Key::Equal,
        KeyCode::Comma => Key::Comma,
        KeyCode::Minus => Key::Minus,
        KeyCode::Period => Key::Dot,
        KeyCode::Slash => Key::Slash,
        KeyCode::LBracket => Key::LeftBracket,
        KeyCode::RBracket => Key::RightBracket,
        KeyCode::Backslash => Key::BackSlash,
        KeyCode::Apostrophe => Key::Quote,
        KeyCode::Grave => Key::BackQuote,
        _ => panic!("Unknown iced code: {:?}", iced_code),
    }
}