diff --git a/example/server.toml b/example/server.toml index f6f724a..06d63c7 100644 --- a/example/server.toml +++ b/example/server.toml @@ -1,5 +1,5 @@ listen-address = "0.0.0.0:5258" -switch-keys = [29, 56, 111] +switch-keys = ["Leftalt"] identity-path = "identity.p12" # Doesn't have to be set. identity-password = "123456789" \ No newline at end of file diff --git a/input/src/event.rs b/input/src/event.rs index 53551d7..7b3861f 100644 --- a/input/src/event.rs +++ b/input/src/event.rs @@ -1,3 +1,9 @@ +mod button; +mod key; + +pub use button::Button; +pub use key::Key; + use crate::glue::{self, input_event, timeval}; use serde::{Deserialize, Serialize}; @@ -5,7 +11,7 @@ use serde::{Deserialize, Serialize}; pub enum Event { MouseScroll { delta: i32 }, MouseMove { axis: Axis, delta: i32 }, - Key { direction: Direction, code: u16 }, + Key { direction: Direction, kind: KeyKind }, Sync, } @@ -23,12 +29,12 @@ impl Event { } => (glue::EV_REL as _, glue::REL_Y as _, delta), Event::Key { direction: Direction::Up, - code, - } => (glue::EV_KEY as _, code, 0), + kind, + } => (glue::EV_KEY as _, kind.to_raw(), 0), Event::Key { direction: Direction::Down, - code, - } => (glue::EV_KEY as _, code, 1), + kind, + } => (glue::EV_KEY as _, kind.to_raw(), 1), Event::Sync => (glue::EV_SYN as _, glue::SYN_REPORT as _, 0), }; @@ -56,11 +62,11 @@ impl Event { }, (glue::EV_KEY, code, 0) => Event::Key { direction: Direction::Up, - code: code as _, + kind: KeyKind::from_raw(code as _)?, }, (glue::EV_KEY, code, 1) => Event::Key { direction: Direction::Down, - code: code as _, + kind: KeyKind::from_raw(code as _)?, }, (glue::EV_SYN, glue::SYN_REPORT, _) => Event::Sync, _ => return None, @@ -81,3 +87,24 @@ pub enum Direction { Up, // The key is released. Down, // The key is pressed. } + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum KeyKind { + Key(Key), + Button(Button), +} + +impl KeyKind { + pub(crate) fn to_raw(&self) -> u16 { + match self { + KeyKind::Key(key) => key.to_raw(), + KeyKind::Button(button) => button.to_raw(), + } + } + + pub(crate) fn from_raw(code: u16) -> Option { + Key::from_raw(code) + .map(KeyKind::Key) + .or_else(|| Button::from_raw(code).map(KeyKind::Button)) + } +} diff --git a/input/src/event/button.rs b/input/src/event/button.rs new file mode 100644 index 0000000..7db22d4 --- /dev/null +++ b/input/src/event/button.rs @@ -0,0 +1,387 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize, Hash)] +pub enum Button { + A, + B, + Back, + Base, + Base2, + Base3, + Base4, + Base5, + Base6, + C, + Dead, + Digi, + DpadDown, + DpadLeft, + DpadRight, + DpadUp, + East, + Extra, + Forward, + Gamepad, + GearDown, + GearUp, + Joystick, + Left, + Middle, + Misc, + Mode, + Mouse, + N0, + N1, + N2, + N3, + N4, + N5, + N6, + N7, + N8, + N9, + North, + Pinkie, + Right, + Select, + Side, + South, + Start, + Stylus, + Stylus2, + Stylus3, + Task, + Thumb, + Thumb2, + Thumbl, + Thumbr, + Tl, + Tl2, + ToolAirbrush, + ToolBrush, + ToolDoubletap, + ToolFinger, + ToolLens, + ToolMouse, + ToolPen, + ToolPencil, + ToolQuadtap, + ToolQuinttap, + ToolRubber, + ToolTripletap, + Top, + Top2, + Touch, + Tr, + Tr2, + Trigger, + TriggerHappy, + TriggerHappy1, + TriggerHappy10, + TriggerHappy11, + TriggerHappy12, + TriggerHappy13, + TriggerHappy14, + TriggerHappy15, + TriggerHappy16, + TriggerHappy17, + TriggerHappy18, + TriggerHappy19, + TriggerHappy2, + TriggerHappy20, + TriggerHappy21, + TriggerHappy22, + TriggerHappy23, + TriggerHappy24, + TriggerHappy25, + TriggerHappy26, + TriggerHappy27, + TriggerHappy28, + TriggerHappy29, + TriggerHappy3, + TriggerHappy30, + TriggerHappy31, + TriggerHappy32, + TriggerHappy33, + TriggerHappy34, + TriggerHappy35, + TriggerHappy36, + TriggerHappy37, + TriggerHappy38, + TriggerHappy39, + TriggerHappy4, + TriggerHappy40, + TriggerHappy5, + TriggerHappy6, + TriggerHappy7, + TriggerHappy8, + TriggerHappy9, + West, + Wheel, + X, + Y, + Z, +} + +impl Button { + pub(crate) fn to_raw(&self) -> u16 { + use Button::*; + + match *self { + A => 0x0130, + B => 0x0131, + Back => 0x0116, + Base => 0x0126, + Base2 => 0x0127, + Base3 => 0x0128, + Base4 => 0x0129, + Base5 => 0x012A, + Base6 => 0x012B, + C => 0x0132, + Dead => 0x012F, + Digi => 0x0140, + DpadDown => 0x0221, + DpadLeft => 0x0222, + DpadRight => 0x0223, + DpadUp => 0x0220, + East => 0x0131, + Extra => 0x0114, + Forward => 0x0115, + Gamepad => 0x0130, + GearDown => 0x0150, + GearUp => 0x0151, + Joystick => 0x0120, + Left => 0x0110, + Middle => 0x0112, + Misc => 0x0100, + Mode => 0x013C, + Mouse => 0x0110, + N0 => 0x0100, + N1 => 0x0101, + N2 => 0x0102, + N3 => 0x0103, + N4 => 0x0104, + N5 => 0x0105, + N6 => 0x0106, + N7 => 0x0107, + N8 => 0x0108, + N9 => 0x0109, + North => 0x0133, + Pinkie => 0x0125, + Right => 0x0111, + Select => 0x013A, + Side => 0x0113, + South => 0x0130, + Start => 0x013B, + Stylus => 0x014B, + Stylus2 => 0x014C, + Stylus3 => 0x0149, + Task => 0x0117, + Thumb => 0x0121, + Thumb2 => 0x0122, + Thumbl => 0x013D, + Thumbr => 0x013E, + Tl => 0x0136, + Tl2 => 0x0138, + ToolAirbrush => 0x0144, + ToolBrush => 0x0142, + ToolDoubletap => 0x014D, + ToolFinger => 0x0145, + ToolLens => 0x0147, + ToolMouse => 0x0146, + ToolPen => 0x0140, + ToolPencil => 0x0143, + ToolQuadtap => 0x014F, + ToolQuinttap => 0x0148, + ToolRubber => 0x0141, + ToolTripletap => 0x014E, + Top => 0x0123, + Top2 => 0x0124, + Touch => 0x014A, + Tr => 0x0137, + Tr2 => 0x0139, + Trigger => 0x0120, + TriggerHappy => 0x02C0, + TriggerHappy1 => 0x02C0, + TriggerHappy10 => 0x02C9, + TriggerHappy11 => 0x02CA, + TriggerHappy12 => 0x02CB, + TriggerHappy13 => 0x02CC, + TriggerHappy14 => 0x02CD, + TriggerHappy15 => 0x02CE, + TriggerHappy16 => 0x02CF, + TriggerHappy17 => 0x02D0, + TriggerHappy18 => 0x02D1, + TriggerHappy19 => 0x02D2, + TriggerHappy2 => 0x02C1, + TriggerHappy20 => 0x02D3, + TriggerHappy21 => 0x02D4, + TriggerHappy22 => 0x02D5, + TriggerHappy23 => 0x02D6, + TriggerHappy24 => 0x02D7, + TriggerHappy25 => 0x02D8, + TriggerHappy26 => 0x02D9, + TriggerHappy27 => 0x02DA, + TriggerHappy28 => 0x02DB, + TriggerHappy29 => 0x02DC, + TriggerHappy3 => 0x02C2, + TriggerHappy30 => 0x02DD, + TriggerHappy31 => 0x02DE, + TriggerHappy32 => 0x02DF, + TriggerHappy33 => 0x02E0, + TriggerHappy34 => 0x02E1, + TriggerHappy35 => 0x02E2, + TriggerHappy36 => 0x02E3, + TriggerHappy37 => 0x02E4, + TriggerHappy38 => 0x02E5, + TriggerHappy39 => 0x02E6, + TriggerHappy4 => 0x02C3, + TriggerHappy40 => 0x02E7, + TriggerHappy5 => 0x02C4, + TriggerHappy6 => 0x02C5, + TriggerHappy7 => 0x02C6, + TriggerHappy8 => 0x02C7, + TriggerHappy9 => 0x02C8, + West => 0x0134, + Wheel => 0x0150, + X => 0x0130, + Y => 0x0150, + Z => 0x0135, + } + } + + pub(crate) fn from_raw(code: u16) -> Option { + use Button::*; + + // This is generated from linux headers, some patterns are unreachable, and we don't care. + #[allow(unreachable_patterns)] + let button = match code { + 0x0130 => A, + 0x0131 => B, + 0x0116 => Back, + 0x0126 => Base, + 0x0127 => Base2, + 0x0128 => Base3, + 0x0129 => Base4, + 0x012A => Base5, + 0x012B => Base6, + 0x0132 => C, + 0x012F => Dead, + 0x0140 => Digi, + 0x0221 => DpadDown, + 0x0222 => DpadLeft, + 0x0223 => DpadRight, + 0x0220 => DpadUp, + 0x0131 => East, + 0x0114 => Extra, + 0x0115 => Forward, + 0x0130 => Gamepad, + 0x0150 => GearDown, + 0x0151 => GearUp, + 0x0120 => Joystick, + 0x0110 => Left, + 0x0112 => Middle, + 0x0100 => Misc, + 0x013C => Mode, + 0x0110 => Mouse, + 0x0100 => N0, + 0x0101 => N1, + 0x0102 => N2, + 0x0103 => N3, + 0x0104 => N4, + 0x0105 => N5, + 0x0106 => N6, + 0x0107 => N7, + 0x0108 => N8, + 0x0109 => N9, + 0x0133 => North, + 0x0125 => Pinkie, + 0x0111 => Right, + 0x013A => Select, + 0x0113 => Side, + 0x0130 => South, + 0x013B => Start, + 0x014B => Stylus, + 0x014C => Stylus2, + 0x0149 => Stylus3, + 0x0117 => Task, + 0x0121 => Thumb, + 0x0122 => Thumb2, + 0x013D => Thumbl, + 0x013E => Thumbr, + 0x0136 => Tl, + 0x0138 => Tl2, + 0x0144 => ToolAirbrush, + 0x0142 => ToolBrush, + 0x014D => ToolDoubletap, + 0x0145 => ToolFinger, + 0x0147 => ToolLens, + 0x0146 => ToolMouse, + 0x0140 => ToolPen, + 0x0143 => ToolPencil, + 0x014F => ToolQuadtap, + 0x0148 => ToolQuinttap, + 0x0141 => ToolRubber, + 0x014E => ToolTripletap, + 0x0123 => Top, + 0x0124 => Top2, + 0x014A => Touch, + 0x0137 => Tr, + 0x0139 => Tr2, + 0x0120 => Trigger, + 0x02C0 => TriggerHappy, + 0x02C0 => TriggerHappy1, + 0x02C9 => TriggerHappy10, + 0x02CA => TriggerHappy11, + 0x02CB => TriggerHappy12, + 0x02CC => TriggerHappy13, + 0x02CD => TriggerHappy14, + 0x02CE => TriggerHappy15, + 0x02CF => TriggerHappy16, + 0x02D0 => TriggerHappy17, + 0x02D1 => TriggerHappy18, + 0x02D2 => TriggerHappy19, + 0x02C1 => TriggerHappy2, + 0x02D3 => TriggerHappy20, + 0x02D4 => TriggerHappy21, + 0x02D5 => TriggerHappy22, + 0x02D6 => TriggerHappy23, + 0x02D7 => TriggerHappy24, + 0x02D8 => TriggerHappy25, + 0x02D9 => TriggerHappy26, + 0x02DA => TriggerHappy27, + 0x02DB => TriggerHappy28, + 0x02DC => TriggerHappy29, + 0x02C2 => TriggerHappy3, + 0x02DD => TriggerHappy30, + 0x02DE => TriggerHappy31, + 0x02DF => TriggerHappy32, + 0x02E0 => TriggerHappy33, + 0x02E1 => TriggerHappy34, + 0x02E2 => TriggerHappy35, + 0x02E3 => TriggerHappy36, + 0x02E4 => TriggerHappy37, + 0x02E5 => TriggerHappy38, + 0x02E6 => TriggerHappy39, + 0x02C3 => TriggerHappy4, + 0x02E7 => TriggerHappy40, + 0x02C4 => TriggerHappy5, + 0x02C5 => TriggerHappy6, + 0x02C6 => TriggerHappy7, + 0x02C7 => TriggerHappy8, + 0x02C8 => TriggerHappy9, + 0x0134 => West, + 0x0150 => Wheel, + 0x0135 => Z, + _ => return None, + }; + + Some(button) + } +} + +impl PartialEq for Button { + fn eq(&self, other: &Self) -> bool { + self.to_raw() == other.to_raw() + } +} diff --git a/input/src/event/key.rs b/input/src/event/key.rs new file mode 100644 index 0000000..7fe3ccd --- /dev/null +++ b/input/src/event/key.rs @@ -0,0 +1,1489 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Copy, Debug, Eq, Serialize, Deserialize, Hash)] +pub enum Key { + A, + Ab, + Addressbook, + Again, + AlsToggle, + Alterase, + Angle, + Apostrophe, + Appselect, + Archive, + AspectRatio, + Assistant, + AttendantOff, + AttendantOn, + AttendantToggle, + Audio, + AudioDesc, + Aux, + B, + Back, + Backslash, + Backspace, + Bassboost, + Battery, + Blue, + Bluetooth, + Bookmarks, + Break, + BrightnessAuto, + BrightnessCycle, + BrightnessMax, + BrightnessMin, + BrightnessToggle, + BrightnessZero, + Brightnessdown, + Brightnessup, + BrlDot1, + BrlDot10, + BrlDot2, + BrlDot3, + BrlDot4, + BrlDot5, + BrlDot6, + BrlDot7, + BrlDot8, + BrlDot9, + Buttonconfig, + C, + Calc, + Calendar, + Camera, + CameraDown, + CameraFocus, + CameraLeft, + CameraRight, + CameraUp, + CameraZoomin, + CameraZoomout, + Cancel, + Capslock, + Cd, + Channel, + Channeldown, + Channelup, + Chat, + Clear, + Close, + Closecd, + Coffee, + Comma, + Compose, + Computer, + Config, + Connect, + ContextMenu, + Controlpanel, + Copy, + Cut, + Cyclewindows, + D, + Dashboard, + Data, + Database, + DelEol, + DelEos, + DelLine, + Delete, + Deletefile, + Digits, + Direction, + Directory, + DisplayOff, + Displaytoggle, + Documents, + Dollar, + Dot, + Down, + Dvd, + E, + Edit, + Editor, + Ejectcd, + Ejectclosecd, + Email, + End, + Enter, + Epg, + Equal, + Esc, + Euro, + Exit, + F, + F1, + F10, + F11, + F12, + F13, + F14, + F15, + F16, + F17, + F18, + F19, + F2, + F20, + F21, + F22, + F23, + F24, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + Fastforward, + Fastreverse, + Favorites, + File, + Finance, + Find, + First, + Fn, + Fn1, + Fn2, + FnB, + FnD, + FnE, + FnEsc, + FnF, + FnF1, + FnF10, + FnF11, + FnF12, + FnF2, + FnF3, + FnF4, + FnF5, + FnF6, + FnF7, + FnF8, + FnF9, + FnS, + Forward, + Forwardmail, + Frameback, + Frameforward, + Front, + FullScreen, + G, + Games, + Goto, + Graphicseditor, + Grave, + Green, + H, + Hangeul, + Hanja, + Help, + Henkan, + Hiragana, + Home, + Homepage, + Hp, + I, + Images, + Info, + InsLine, + Insert, + Iso, + J, + Journal, + K, + Katakana, + Katakanahiragana, + KbdLayoutNext, + KbdLcdMenu1, + KbdLcdMenu2, + KbdLcdMenu3, + KbdLcdMenu4, + KbdLcdMenu5, + Kbdillumdown, + Kbdillumtoggle, + Kbdillumup, + KbdinputassistAccept, + KbdinputassistCancel, + KbdinputassistNext, + KbdinputassistNextgroup, + KbdinputassistPrev, + KbdinputassistPrevgroup, + Keyboard, + Kp0, + Kp1, + Kp2, + Kp3, + Kp4, + Kp5, + Kp6, + Kp7, + Kp8, + Kp9, + Kpasterisk, + Kpcomma, + Kpdot, + Kpenter, + Kpequal, + Kpjpcomma, + Kpleftparen, + Kpminus, + Kpplus, + Kpplusminus, + Kprightparen, + Kpslash, + L, + Language, + Last, + Left, + LeftDown, + LeftUp, + Leftalt, + Leftbrace, + Leftctrl, + Leftmeta, + Leftshift, + LightsToggle, + Linefeed, + List, + Logoff, + M, + Macro, + Macro1, + Macro10, + Macro11, + Macro12, + Macro13, + Macro14, + Macro15, + Macro16, + Macro17, + Macro18, + Macro19, + Macro2, + Macro20, + Macro21, + Macro22, + Macro23, + Macro24, + Macro25, + Macro26, + Macro27, + Macro28, + Macro29, + Macro3, + Macro30, + Macro4, + Macro5, + Macro6, + Macro7, + Macro8, + Macro9, + MacroPreset1, + MacroPreset2, + MacroPreset3, + MacroPresetCycle, + MacroRecordStart, + MacroRecordStop, + Mail, + Media, + MediaRepeat, + MediaTopMenu, + Memo, + Menu, + Messenger, + Mhp, + Micmute, + Minus, + Mode, + Move, + Mp3, + Msdos, + Muhenkan, + Mute, + N, + N0, + N1, + N102nd, + N10channelsdown, + N10channelsup, + N2, + N3, + N3dMode, + N4, + N5, + N6, + N7, + N8, + N9, + New, + News, + Next, + NextFavorite, + Nextsong, + Numeric0, + Numeric1, + Numeric11, + Numeric12, + Numeric2, + Numeric3, + Numeric4, + Numeric5, + Numeric6, + Numeric7, + Numeric8, + Numeric9, + NumericA, + NumericB, + NumericC, + NumericD, + NumericPound, + NumericStar, + Numlock, + O, + Ok, + OnscreenKeyboard, + Open, + Option, + P, + Pagedown, + Pageup, + Paste, + Pause, + PauseRecord, + Pausecd, + Pc, + Phone, + Play, + Playcd, + Player, + Playpause, + Power, + Power2, + Presentation, + Previous, + Previoussong, + Print, + PrivacyScreenToggle, + Prog1, + Prog2, + Prog3, + Prog4, + Program, + Props, + Pvr, + Q, + Question, + R, + Radio, + Record, + Red, + Redo, + Refresh, + Reply, + Reserved, + Restart, + Rewind, + Rfkill, + Right, + RightDown, + RightUp, + Rightalt, + Rightbrace, + Rightctrl, + Rightmeta, + Rightshift, + Ro, + RootMenu, + RotateDisplay, + RotateLockToggle, + S, + Sat, + Sat2, + Save, + Scale, + Screen, + Screenlock, + Screensaver, + Scrolldown, + Scrolllock, + Scrollup, + Search, + Select, + SelectiveScreenshot, + Semicolon, + Send, + Sendfile, + Setup, + Shop, + Shuffle, + Slash, + Sleep, + Slow, + Slowreverse, + Sound, + Space, + Spellcheck, + Sport, + Spreadsheet, + Stop, + StopRecord, + Stopcd, + Subtitle, + Suspend, + Switchvideomode, + Sysrq, + T, + Tab, + Tape, + Taskmanager, + Teen, + Text, + Time, + Title, + TouchpadOff, + TouchpadOn, + TouchpadToggle, + Tuner, + Tv, + Tv2, + Twen, + U, + Undo, + Unknown, + Unmute, + Up, + Uwb, + V, + Vcr, + Vcr2, + Vendor, + Video, + VideoNext, + VideoPrev, + Videophone, + Vod, + Voicecommand, + Voicemail, + Volumedown, + Volumeup, + W, + Wakeup, + Wimax, + Wlan, + Wordprocessor, + WpsButton, + Wwan, + Www, + X, + Xfer, + Y, + Yellow, + Yen, + Z, + Zenkakuhankaku, + Zoom, + Zoomin, + Zoomout, + Zoomreset, +} + +impl Key { + pub(crate) fn to_raw(&self) -> u16 { + use Key::*; + + match *self { + A => 0x001E, + Ab => 0x0196, + Addressbook => 0x01AD, + Again => 0x0081, + AlsToggle => 0x0230, + Alterase => 0x00DE, + Angle => 0x0173, + Apostrophe => 0x0028, + Appselect => 0x0244, + Archive => 0x0169, + AspectRatio => 0x0177, + Assistant => 0x0247, + AttendantOff => 0x021C, + AttendantOn => 0x021B, + AttendantToggle => 0x021D, + Audio => 0x0188, + AudioDesc => 0x026E, + Aux => 0x0186, + B => 0x0030, + Back => 0x009E, + Backslash => 0x002B, + Backspace => 0x000E, + Bassboost => 0x00D1, + Battery => 0x00EC, + Blue => 0x0191, + Bluetooth => 0x00ED, + Bookmarks => 0x009C, + Break => 0x019B, + BrightnessAuto => 0x00F4, + BrightnessCycle => 0x00F3, + BrightnessMax => 0x0251, + BrightnessMin => 0x0250, + BrightnessToggle => 0x01AF, + BrightnessZero => 0x00F4, + Brightnessdown => 0x00E0, + Brightnessup => 0x00E1, + BrlDot1 => 0x01F1, + BrlDot10 => 0x01FA, + BrlDot2 => 0x01F2, + BrlDot3 => 0x01F3, + BrlDot4 => 0x01F4, + BrlDot5 => 0x01F5, + BrlDot6 => 0x01F6, + BrlDot7 => 0x01F7, + BrlDot8 => 0x01F8, + BrlDot9 => 0x01F9, + Buttonconfig => 0x0240, + C => 0x002E, + Calc => 0x008C, + Calendar => 0x018D, + Camera => 0x00D4, + CameraDown => 0x0218, + CameraFocus => 0x0210, + CameraLeft => 0x0219, + CameraRight => 0x021A, + CameraUp => 0x0217, + CameraZoomin => 0x0215, + CameraZoomout => 0x0216, + Cancel => 0x00DF, + Capslock => 0x003A, + Cd => 0x017F, + Channel => 0x016B, + Channeldown => 0x0193, + Channelup => 0x0192, + Chat => 0x00D8, + Clear => 0x0163, + Close => 0x00CE, + Closecd => 0x00A0, + Coffee => 0x0098, + Comma => 0x0033, + Compose => 0x007F, + Computer => 0x009D, + Config => 0x00AB, + Connect => 0x00DA, + ContextMenu => 0x01B6, + Controlpanel => 0x0243, + Copy => 0x0085, + Cut => 0x0089, + Cyclewindows => 0x009A, + D => 0x0020, + Dashboard => 0x00CC, + Data => 0x0277, + Database => 0x01AA, + DelEol => 0x01C0, + DelEos => 0x01C1, + DelLine => 0x01C3, + Delete => 0x006F, + Deletefile => 0x0092, + Digits => 0x019D, + Direction => 0x0099, + Directory => 0x018A, + DisplayOff => 0x00F5, + Displaytoggle => 0x01AF, + Documents => 0x00EB, + Dollar => 0x01B2, + Dot => 0x0034, + Down => 0x006C, + Dvd => 0x0185, + E => 0x0012, + Edit => 0x00B0, + Editor => 0x01A6, + Ejectcd => 0x00A1, + Ejectclosecd => 0x00A2, + Email => 0x00D7, + End => 0x006B, + Enter => 0x001C, + Epg => 0x016D, + Equal => 0x000D, + Esc => 0x0001, + Euro => 0x01B3, + Exit => 0x00AE, + F => 0x0021, + F1 => 0x003B, + F10 => 0x0044, + F11 => 0x0057, + F12 => 0x0058, + F13 => 0x00B7, + F14 => 0x00B8, + F15 => 0x00B9, + F16 => 0x00BA, + F17 => 0x00BB, + F18 => 0x00BC, + F19 => 0x00BD, + F2 => 0x003C, + F20 => 0x00BE, + F21 => 0x00BF, + F22 => 0x00C0, + F23 => 0x00C1, + F24 => 0x00C2, + F3 => 0x003D, + F4 => 0x003E, + F5 => 0x003F, + F6 => 0x0040, + F7 => 0x0041, + F8 => 0x0042, + F9 => 0x0043, + Fastforward => 0x00D0, + Fastreverse => 0x0275, + Favorites => 0x016C, + File => 0x0090, + Finance => 0x00DB, + Find => 0x0088, + First => 0x0194, + Fn => 0x01D0, + Fn1 => 0x01DE, + Fn2 => 0x01DF, + FnB => 0x01E4, + FnD => 0x01E0, + FnE => 0x01E1, + FnEsc => 0x01D1, + FnF => 0x01E2, + FnF1 => 0x01D2, + FnF10 => 0x01DB, + FnF11 => 0x01DC, + FnF12 => 0x01DD, + FnF2 => 0x01D3, + FnF3 => 0x01D4, + FnF4 => 0x01D5, + FnF5 => 0x01D6, + FnF6 => 0x01D7, + FnF7 => 0x01D8, + FnF8 => 0x01D9, + FnF9 => 0x01DA, + FnS => 0x01E3, + Forward => 0x009F, + Forwardmail => 0x00E9, + Frameback => 0x01B4, + Frameforward => 0x01B5, + Front => 0x0084, + FullScreen => 0x0174, + G => 0x0022, + Games => 0x01A1, + Goto => 0x0162, + Graphicseditor => 0x01A8, + Grave => 0x0029, + Green => 0x018F, + H => 0x0023, + Hangeul => 0x007A, + Hanja => 0x007B, + Help => 0x008A, + Henkan => 0x005C, + Hiragana => 0x005B, + Home => 0x0066, + Homepage => 0x00AC, + Hp => 0x00D3, + I => 0x0017, + Images => 0x01BA, + Info => 0x0166, + InsLine => 0x01C2, + Insert => 0x006E, + Iso => 0x00AA, + J => 0x0024, + Journal => 0x0242, + K => 0x0025, + Katakana => 0x005A, + Katakanahiragana => 0x005D, + KbdLayoutNext => 0x0248, + KbdLcdMenu1 => 0x02B8, + KbdLcdMenu2 => 0x02B9, + KbdLcdMenu3 => 0x02BA, + KbdLcdMenu4 => 0x02BB, + KbdLcdMenu5 => 0x02BC, + Kbdillumdown => 0x00E5, + Kbdillumtoggle => 0x00E4, + Kbdillumup => 0x00E6, + KbdinputassistAccept => 0x0264, + KbdinputassistCancel => 0x0265, + KbdinputassistNext => 0x0261, + KbdinputassistNextgroup => 0x0263, + KbdinputassistPrev => 0x0260, + KbdinputassistPrevgroup => 0x0262, + Keyboard => 0x0176, + Kp0 => 0x0052, + Kp1 => 0x004F, + Kp2 => 0x0050, + Kp3 => 0x0051, + Kp4 => 0x004B, + Kp5 => 0x004C, + Kp6 => 0x004D, + Kp7 => 0x0047, + Kp8 => 0x0048, + Kp9 => 0x0049, + Kpasterisk => 0x0037, + Kpcomma => 0x0079, + Kpdot => 0x0053, + Kpenter => 0x0060, + Kpequal => 0x0075, + Kpjpcomma => 0x005F, + Kpleftparen => 0x00B3, + Kpminus => 0x004A, + Kpplus => 0x004E, + Kpplusminus => 0x0076, + Kprightparen => 0x00B4, + Kpslash => 0x0062, + L => 0x0026, + Language => 0x0170, + Last => 0x0195, + Left => 0x0069, + LeftDown => 0x0269, + LeftUp => 0x0268, + Leftalt => 0x0038, + Leftbrace => 0x001A, + Leftctrl => 0x001D, + Leftmeta => 0x007D, + Leftshift => 0x002A, + LightsToggle => 0x021E, + Linefeed => 0x0065, + List => 0x018B, + Logoff => 0x01B1, + M => 0x0032, + Macro => 0x0070, + Macro1 => 0x0290, + Macro10 => 0x0299, + Macro11 => 0x029A, + Macro12 => 0x029B, + Macro13 => 0x029C, + Macro14 => 0x029D, + Macro15 => 0x029E, + Macro16 => 0x029F, + Macro17 => 0x02A0, + Macro18 => 0x02A1, + Macro19 => 0x02A2, + Macro2 => 0x0291, + Macro20 => 0x02A3, + Macro21 => 0x02A4, + Macro22 => 0x02A5, + Macro23 => 0x02A6, + Macro24 => 0x02A7, + Macro25 => 0x02A8, + Macro26 => 0x02A9, + Macro27 => 0x02AA, + Macro28 => 0x02AB, + Macro29 => 0x02AC, + Macro3 => 0x0292, + Macro30 => 0x02AD, + Macro4 => 0x0293, + Macro5 => 0x0294, + Macro6 => 0x0295, + Macro7 => 0x0296, + Macro8 => 0x0297, + Macro9 => 0x0298, + MacroPreset1 => 0x02B3, + MacroPreset2 => 0x02B4, + MacroPreset3 => 0x02B5, + MacroPresetCycle => 0x02B2, + MacroRecordStart => 0x02B0, + MacroRecordStop => 0x02B1, + Mail => 0x009B, + Media => 0x00E2, + MediaRepeat => 0x01B7, + MediaTopMenu => 0x026B, + Memo => 0x018C, + Menu => 0x008B, + Messenger => 0x01AE, + Mhp => 0x016F, + Micmute => 0x00F8, + Minus => 0x000C, + Mode => 0x0175, + Move => 0x00AF, + Mp3 => 0x0187, + Msdos => 0x0097, + Muhenkan => 0x005E, + Mute => 0x0071, + N => 0x0031, + N0 => 0x000B, + N1 => 0x0002, + N102nd => 0x0056, + N10channelsdown => 0x01B9, + N10channelsup => 0x01B8, + N2 => 0x0003, + N3 => 0x0004, + N3dMode => 0x026F, + N4 => 0x0005, + N5 => 0x0006, + N6 => 0x0007, + N7 => 0x0008, + N8 => 0x0009, + N9 => 0x000A, + New => 0x00B5, + News => 0x01AB, + Next => 0x0197, + NextFavorite => 0x0270, + Nextsong => 0x00A3, + Numeric0 => 0x0200, + Numeric1 => 0x0201, + Numeric11 => 0x026C, + Numeric12 => 0x026D, + Numeric2 => 0x0202, + Numeric3 => 0x0203, + Numeric4 => 0x0204, + Numeric5 => 0x0205, + Numeric6 => 0x0206, + Numeric7 => 0x0207, + Numeric8 => 0x0208, + Numeric9 => 0x0209, + NumericA => 0x020C, + NumericB => 0x020D, + NumericC => 0x020E, + NumericD => 0x020F, + NumericPound => 0x020B, + NumericStar => 0x020A, + Numlock => 0x0045, + O => 0x0018, + Ok => 0x0160, + OnscreenKeyboard => 0x0278, + Open => 0x0086, + Option => 0x0165, + P => 0x0019, + Pagedown => 0x006D, + Pageup => 0x0068, + Paste => 0x0087, + Pause => 0x0077, + PauseRecord => 0x0272, + Pausecd => 0x00C9, + Pc => 0x0178, + Phone => 0x00A9, + Play => 0x00CF, + Playcd => 0x00C8, + Player => 0x0183, + Playpause => 0x00A4, + Power => 0x0074, + Power2 => 0x0164, + Presentation => 0x01A9, + Previous => 0x019C, + Previoussong => 0x00A5, + Print => 0x00D2, + PrivacyScreenToggle => 0x0279, + Prog1 => 0x0094, + Prog2 => 0x0095, + Prog3 => 0x00CA, + Prog4 => 0x00CB, + Program => 0x016A, + Props => 0x0082, + Pvr => 0x016E, + Q => 0x0010, + Question => 0x00D6, + R => 0x0013, + Radio => 0x0181, + Record => 0x00A7, + Red => 0x018E, + Redo => 0x00B6, + Refresh => 0x00AD, + Reply => 0x00E8, + Reserved => 0x0000, + Restart => 0x0198, + Rewind => 0x00A8, + Rfkill => 0x00F7, + Right => 0x006A, + RightDown => 0x0267, + RightUp => 0x0266, + Rightalt => 0x0064, + Rightbrace => 0x001B, + Rightctrl => 0x0061, + Rightmeta => 0x007E, + Rightshift => 0x0036, + Ro => 0x0059, + RootMenu => 0x026A, + RotateDisplay => 0x0099, + RotateLockToggle => 0x0231, + S => 0x001F, + Sat => 0x017D, + Sat2 => 0x017E, + Save => 0x00EA, + Scale => 0x0078, + Screen => 0x0177, + Screenlock => 0x0098, + Screensaver => 0x0245, + Scrolldown => 0x00B2, + Scrolllock => 0x0046, + Scrollup => 0x00B1, + Search => 0x00D9, + Select => 0x0161, + SelectiveScreenshot => 0x027A, + Semicolon => 0x0027, + Send => 0x00E7, + Sendfile => 0x0091, + Setup => 0x008D, + Shop => 0x00DD, + Shuffle => 0x019A, + Slash => 0x0035, + Sleep => 0x008E, + Slow => 0x0199, + Slowreverse => 0x0276, + Sound => 0x00D5, + Space => 0x0039, + Spellcheck => 0x01B0, + Sport => 0x00DC, + Spreadsheet => 0x01A7, + Stop => 0x0080, + StopRecord => 0x0271, + Stopcd => 0x00A6, + Subtitle => 0x0172, + Suspend => 0x00CD, + Switchvideomode => 0x00E3, + Sysrq => 0x0063, + T => 0x0014, + Tab => 0x000F, + Tape => 0x0180, + Taskmanager => 0x0241, + Teen => 0x019E, + Text => 0x0184, + Time => 0x0167, + Title => 0x0171, + TouchpadOff => 0x0214, + TouchpadOn => 0x0213, + TouchpadToggle => 0x0212, + Tuner => 0x0182, + Tv => 0x0179, + Tv2 => 0x017A, + Twen => 0x019F, + U => 0x0016, + Undo => 0x0083, + Unknown => 0x00F0, + Unmute => 0x0274, + Up => 0x0067, + Uwb => 0x00EF, + V => 0x002F, + Vcr => 0x017B, + Vcr2 => 0x017C, + Vendor => 0x0168, + Video => 0x0189, + VideoNext => 0x00F1, + VideoPrev => 0x00F2, + Videophone => 0x01A0, + Vod => 0x0273, + Voicecommand => 0x0246, + Voicemail => 0x01AC, + Volumedown => 0x0072, + Volumeup => 0x0073, + W => 0x0011, + Wakeup => 0x008F, + Wimax => 0x00F6, + Wlan => 0x00EE, + Wordprocessor => 0x01A5, + WpsButton => 0x0211, + Wwan => 0x00F6, + Www => 0x0096, + X => 0x002D, + Xfer => 0x0093, + Y => 0x0015, + Yellow => 0x0190, + Yen => 0x007C, + Z => 0x002C, + Zenkakuhankaku => 0x0055, + Zoom => 0x0174, + Zoomin => 0x01A2, + Zoomout => 0x01A3, + Zoomreset => 0x01A4, + } + } + + pub(crate) fn from_raw(code: u16) -> Option { + use Key::*; + + // This is generated from linux headers, some patterns are unreachable, and we don't care. + #[allow(unreachable_patterns)] + let key = match code { + 0x001E => A, + 0x0196 => Ab, + 0x01AD => Addressbook, + 0x0081 => Again, + 0x0230 => AlsToggle, + 0x00DE => Alterase, + 0x0173 => Angle, + 0x0028 => Apostrophe, + 0x0244 => Appselect, + 0x0169 => Archive, + 0x0177 => AspectRatio, + 0x0247 => Assistant, + 0x021C => AttendantOff, + 0x021B => AttendantOn, + 0x021D => AttendantToggle, + 0x0188 => Audio, + 0x026E => AudioDesc, + 0x0186 => Aux, + 0x0030 => B, + 0x009E => Back, + 0x002B => Backslash, + 0x000E => Backspace, + 0x00D1 => Bassboost, + 0x00EC => Battery, + 0x0191 => Blue, + 0x00ED => Bluetooth, + 0x009C => Bookmarks, + 0x019B => Break, + 0x00F4 => BrightnessAuto, + 0x00F3 => BrightnessCycle, + 0x0251 => BrightnessMax, + 0x0250 => BrightnessMin, + 0x00E0 => Brightnessdown, + 0x00E1 => Brightnessup, + 0x01F1 => BrlDot1, + 0x01FA => BrlDot10, + 0x01F2 => BrlDot2, + 0x01F3 => BrlDot3, + 0x01F4 => BrlDot4, + 0x01F5 => BrlDot5, + 0x01F6 => BrlDot6, + 0x01F7 => BrlDot7, + 0x01F8 => BrlDot8, + 0x01F9 => BrlDot9, + 0x0240 => Buttonconfig, + 0x002E => C, + 0x008C => Calc, + 0x018D => Calendar, + 0x00D4 => Camera, + 0x0218 => CameraDown, + 0x0210 => CameraFocus, + 0x0219 => CameraLeft, + 0x021A => CameraRight, + 0x0217 => CameraUp, + 0x0215 => CameraZoomin, + 0x0216 => CameraZoomout, + 0x00DF => Cancel, + 0x003A => Capslock, + 0x017F => Cd, + 0x016B => Channel, + 0x0193 => Channeldown, + 0x0192 => Channelup, + 0x00D8 => Chat, + 0x0163 => Clear, + 0x00CE => Close, + 0x00A0 => Closecd, + 0x0098 => Coffee, + 0x0033 => Comma, + 0x007F => Compose, + 0x009D => Computer, + 0x00AB => Config, + 0x00DA => Connect, + 0x01B6 => ContextMenu, + 0x0243 => Controlpanel, + 0x0085 => Copy, + 0x0089 => Cut, + 0x009A => Cyclewindows, + 0x0020 => D, + 0x00CC => Dashboard, + 0x0277 => Data, + 0x01AA => Database, + 0x01C0 => DelEol, + 0x01C1 => DelEos, + 0x01C3 => DelLine, + 0x006F => Delete, + 0x0092 => Deletefile, + 0x019D => Digits, + 0x018A => Directory, + 0x00F5 => DisplayOff, + 0x01AF => Displaytoggle, + 0x00EB => Documents, + 0x01B2 => Dollar, + 0x0034 => Dot, + 0x006C => Down, + 0x0185 => Dvd, + 0x0012 => E, + 0x00B0 => Edit, + 0x01A6 => Editor, + 0x00A1 => Ejectcd, + 0x00A2 => Ejectclosecd, + 0x00D7 => Email, + 0x006B => End, + 0x001C => Enter, + 0x016D => Epg, + 0x000D => Equal, + 0x0001 => Esc, + 0x01B3 => Euro, + 0x00AE => Exit, + 0x0021 => F, + 0x003B => F1, + 0x0044 => F10, + 0x0057 => F11, + 0x0058 => F12, + 0x00B7 => F13, + 0x00B8 => F14, + 0x00B9 => F15, + 0x00BA => F16, + 0x00BB => F17, + 0x00BC => F18, + 0x00BD => F19, + 0x003C => F2, + 0x00BE => F20, + 0x00BF => F21, + 0x00C0 => F22, + 0x00C1 => F23, + 0x00C2 => F24, + 0x003D => F3, + 0x003E => F4, + 0x003F => F5, + 0x0040 => F6, + 0x0041 => F7, + 0x0042 => F8, + 0x0043 => F9, + 0x00D0 => Fastforward, + 0x0275 => Fastreverse, + 0x016C => Favorites, + 0x0090 => File, + 0x00DB => Finance, + 0x0088 => Find, + 0x0194 => First, + 0x01D0 => Fn, + 0x01DE => Fn1, + 0x01DF => Fn2, + 0x01E4 => FnB, + 0x01E0 => FnD, + 0x01E1 => FnE, + 0x01D1 => FnEsc, + 0x01E2 => FnF, + 0x01D2 => FnF1, + 0x01DB => FnF10, + 0x01DC => FnF11, + 0x01DD => FnF12, + 0x01D3 => FnF2, + 0x01D4 => FnF3, + 0x01D5 => FnF4, + 0x01D6 => FnF5, + 0x01D7 => FnF6, + 0x01D8 => FnF7, + 0x01D9 => FnF8, + 0x01DA => FnF9, + 0x01E3 => FnS, + 0x009F => Forward, + 0x00E9 => Forwardmail, + 0x01B4 => Frameback, + 0x01B5 => Frameforward, + 0x0084 => Front, + 0x0174 => FullScreen, + 0x0022 => G, + 0x01A1 => Games, + 0x0162 => Goto, + 0x01A8 => Graphicseditor, + 0x0029 => Grave, + 0x018F => Green, + 0x0023 => H, + 0x007A => Hangeul, + 0x007B => Hanja, + 0x008A => Help, + 0x005C => Henkan, + 0x005B => Hiragana, + 0x0066 => Home, + 0x00AC => Homepage, + 0x00D3 => Hp, + 0x0017 => I, + 0x01BA => Images, + 0x0166 => Info, + 0x01C2 => InsLine, + 0x006E => Insert, + 0x00AA => Iso, + 0x0024 => J, + 0x0242 => Journal, + 0x0025 => K, + 0x005A => Katakana, + 0x005D => Katakanahiragana, + 0x0248 => KbdLayoutNext, + 0x02B8 => KbdLcdMenu1, + 0x02B9 => KbdLcdMenu2, + 0x02BA => KbdLcdMenu3, + 0x02BB => KbdLcdMenu4, + 0x02BC => KbdLcdMenu5, + 0x00E5 => Kbdillumdown, + 0x00E4 => Kbdillumtoggle, + 0x00E6 => Kbdillumup, + 0x0264 => KbdinputassistAccept, + 0x0265 => KbdinputassistCancel, + 0x0261 => KbdinputassistNext, + 0x0263 => KbdinputassistNextgroup, + 0x0260 => KbdinputassistPrev, + 0x0262 => KbdinputassistPrevgroup, + 0x0176 => Keyboard, + 0x0052 => Kp0, + 0x004F => Kp1, + 0x0050 => Kp2, + 0x0051 => Kp3, + 0x004B => Kp4, + 0x004C => Kp5, + 0x004D => Kp6, + 0x0047 => Kp7, + 0x0048 => Kp8, + 0x0049 => Kp9, + 0x0037 => Kpasterisk, + 0x0079 => Kpcomma, + 0x0053 => Kpdot, + 0x0060 => Kpenter, + 0x0075 => Kpequal, + 0x005F => Kpjpcomma, + 0x00B3 => Kpleftparen, + 0x004A => Kpminus, + 0x004E => Kpplus, + 0x0076 => Kpplusminus, + 0x00B4 => Kprightparen, + 0x0062 => Kpslash, + 0x0026 => L, + 0x0170 => Language, + 0x0195 => Last, + 0x0069 => Left, + 0x0269 => LeftDown, + 0x0268 => LeftUp, + 0x0038 => Leftalt, + 0x001A => Leftbrace, + 0x001D => Leftctrl, + 0x007D => Leftmeta, + 0x002A => Leftshift, + 0x021E => LightsToggle, + 0x0065 => Linefeed, + 0x018B => List, + 0x01B1 => Logoff, + 0x0032 => M, + 0x0070 => Macro, + 0x0290 => Macro1, + 0x0299 => Macro10, + 0x029A => Macro11, + 0x029B => Macro12, + 0x029C => Macro13, + 0x029D => Macro14, + 0x029E => Macro15, + 0x029F => Macro16, + 0x02A0 => Macro17, + 0x02A1 => Macro18, + 0x02A2 => Macro19, + 0x0291 => Macro2, + 0x02A3 => Macro20, + 0x02A4 => Macro21, + 0x02A5 => Macro22, + 0x02A6 => Macro23, + 0x02A7 => Macro24, + 0x02A8 => Macro25, + 0x02A9 => Macro26, + 0x02AA => Macro27, + 0x02AB => Macro28, + 0x02AC => Macro29, + 0x0292 => Macro3, + 0x02AD => Macro30, + 0x0293 => Macro4, + 0x0294 => Macro5, + 0x0295 => Macro6, + 0x0296 => Macro7, + 0x0297 => Macro8, + 0x0298 => Macro9, + 0x02B3 => MacroPreset1, + 0x02B4 => MacroPreset2, + 0x02B5 => MacroPreset3, + 0x02B2 => MacroPresetCycle, + 0x02B0 => MacroRecordStart, + 0x02B1 => MacroRecordStop, + 0x009B => Mail, + 0x00E2 => Media, + 0x01B7 => MediaRepeat, + 0x026B => MediaTopMenu, + 0x018C => Memo, + 0x008B => Menu, + 0x01AE => Messenger, + 0x016F => Mhp, + 0x00F8 => Micmute, + 0x000C => Minus, + 0x0175 => Mode, + 0x00AF => Move, + 0x0187 => Mp3, + 0x0097 => Msdos, + 0x005E => Muhenkan, + 0x0071 => Mute, + 0x0031 => N, + 0x000B => N0, + 0x0002 => N1, + 0x0056 => N102nd, + 0x01B9 => N10channelsdown, + 0x01B8 => N10channelsup, + 0x0003 => N2, + 0x0004 => N3, + 0x026F => N3dMode, + 0x0005 => N4, + 0x0006 => N5, + 0x0007 => N6, + 0x0008 => N7, + 0x0009 => N8, + 0x000A => N9, + 0x00B5 => New, + 0x01AB => News, + 0x0197 => Next, + 0x0270 => NextFavorite, + 0x00A3 => Nextsong, + 0x0200 => Numeric0, + 0x0201 => Numeric1, + 0x026C => Numeric11, + 0x026D => Numeric12, + 0x0202 => Numeric2, + 0x0203 => Numeric3, + 0x0204 => Numeric4, + 0x0205 => Numeric5, + 0x0206 => Numeric6, + 0x0207 => Numeric7, + 0x0208 => Numeric8, + 0x0209 => Numeric9, + 0x020C => NumericA, + 0x020D => NumericB, + 0x020E => NumericC, + 0x020F => NumericD, + 0x020B => NumericPound, + 0x020A => NumericStar, + 0x0045 => Numlock, + 0x0018 => O, + 0x0160 => Ok, + 0x0278 => OnscreenKeyboard, + 0x0086 => Open, + 0x0165 => Option, + 0x0019 => P, + 0x006D => Pagedown, + 0x0068 => Pageup, + 0x0087 => Paste, + 0x0077 => Pause, + 0x0272 => PauseRecord, + 0x00C9 => Pausecd, + 0x0178 => Pc, + 0x00A9 => Phone, + 0x00CF => Play, + 0x00C8 => Playcd, + 0x0183 => Player, + 0x00A4 => Playpause, + 0x0074 => Power, + 0x0164 => Power2, + 0x01A9 => Presentation, + 0x019C => Previous, + 0x00A5 => Previoussong, + 0x00D2 => Print, + 0x0279 => PrivacyScreenToggle, + 0x0094 => Prog1, + 0x0095 => Prog2, + 0x00CA => Prog3, + 0x00CB => Prog4, + 0x016A => Program, + 0x0082 => Props, + 0x016E => Pvr, + 0x0010 => Q, + 0x00D6 => Question, + 0x0013 => R, + 0x0181 => Radio, + 0x00A7 => Record, + 0x018E => Red, + 0x00B6 => Redo, + 0x00AD => Refresh, + 0x00E8 => Reply, + 0x0000 => Reserved, + 0x0198 => Restart, + 0x00A8 => Rewind, + 0x00F7 => Rfkill, + 0x006A => Right, + 0x0267 => RightDown, + 0x0266 => RightUp, + 0x0064 => Rightalt, + 0x001B => Rightbrace, + 0x0061 => Rightctrl, + 0x007E => Rightmeta, + 0x0036 => Rightshift, + 0x0059 => Ro, + 0x026A => RootMenu, + 0x0099 => RotateDisplay, + 0x0231 => RotateLockToggle, + 0x001F => S, + 0x017D => Sat, + 0x017E => Sat2, + 0x00EA => Save, + 0x0078 => Scale, + 0x0245 => Screensaver, + 0x00B2 => Scrolldown, + 0x0046 => Scrolllock, + 0x00B1 => Scrollup, + 0x00D9 => Search, + 0x0161 => Select, + 0x027A => SelectiveScreenshot, + 0x0027 => Semicolon, + 0x00E7 => Send, + 0x0091 => Sendfile, + 0x008D => Setup, + 0x00DD => Shop, + 0x019A => Shuffle, + 0x0035 => Slash, + 0x008E => Sleep, + 0x0199 => Slow, + 0x0276 => Slowreverse, + 0x00D5 => Sound, + 0x0039 => Space, + 0x01B0 => Spellcheck, + 0x00DC => Sport, + 0x01A7 => Spreadsheet, + 0x0080 => Stop, + 0x0271 => StopRecord, + 0x00A6 => Stopcd, + 0x0172 => Subtitle, + 0x00CD => Suspend, + 0x00E3 => Switchvideomode, + 0x0063 => Sysrq, + 0x0014 => T, + 0x000F => Tab, + 0x0180 => Tape, + 0x0241 => Taskmanager, + 0x019E => Teen, + 0x0184 => Text, + 0x0167 => Time, + 0x0171 => Title, + 0x0214 => TouchpadOff, + 0x0213 => TouchpadOn, + 0x0212 => TouchpadToggle, + 0x0182 => Tuner, + 0x0179 => Tv, + 0x017A => Tv2, + 0x019F => Twen, + 0x0016 => U, + 0x0083 => Undo, + 0x00F0 => Unknown, + 0x0274 => Unmute, + 0x0067 => Up, + 0x00EF => Uwb, + 0x002F => V, + 0x017B => Vcr, + 0x017C => Vcr2, + 0x0168 => Vendor, + 0x0189 => Video, + 0x00F1 => VideoNext, + 0x00F2 => VideoPrev, + 0x01A0 => Videophone, + 0x0273 => Vod, + 0x0246 => Voicecommand, + 0x01AC => Voicemail, + 0x0072 => Volumedown, + 0x0073 => Volumeup, + 0x0011 => W, + 0x008F => Wakeup, + 0x00EE => Wlan, + 0x01A5 => Wordprocessor, + 0x0211 => WpsButton, + 0x00F6 => Wwan, + 0x0096 => Www, + 0x002D => X, + 0x0093 => Xfer, + 0x0015 => Y, + 0x0190 => Yellow, + 0x007C => Yen, + 0x002C => Z, + 0x0055 => Zenkakuhankaku, + 0x01A2 => Zoomin, + 0x01A3 => Zoomout, + 0x01A4 => Zoomreset, + _ => return None, + }; + + Some(key) + } +} + +impl PartialEq for Key { + fn eq(&self, other: &Self) -> bool { + self.to_raw() == other.to_raw() + } +} diff --git a/input/src/lib.rs b/input/src/lib.rs index f525dfe..bc010bd 100644 --- a/input/src/lib.rs +++ b/input/src/lib.rs @@ -4,6 +4,6 @@ mod event_reader; mod event_writer; mod glue; -pub use event::{Axis, Direction, Event}; +pub use event::{Axis, Button, Direction, Event, Key, KeyKind}; pub use event_manager::EventManager; pub use event_writer::EventWriter; diff --git a/server/src/config.rs b/server/src/config.rs index 9314873..78a113a 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -1,3 +1,4 @@ +use input::Key; use serde::Deserialize; use std::collections::HashSet; use std::net::SocketAddr; @@ -7,7 +8,7 @@ use std::path::PathBuf; #[serde(rename_all = "kebab-case")] pub struct Config { pub listen_address: SocketAddr, - pub switch_keys: HashSet, + pub switch_keys: HashSet, pub identity_path: PathBuf, #[serde(default)] pub identity_password: String, diff --git a/server/src/main.rs b/server/src/main.rs index bc08edd..872bedd 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -2,7 +2,7 @@ mod config; use anyhow::{Context, Error}; use config::Config; -use input::{Direction, Event, EventManager}; +use input::{Direction, Event, EventManager, Key, KeyKind}; use net::{self, Message, PROTOCOL_VERSION}; use std::collections::{HashMap, HashSet}; use std::convert::Infallible; @@ -49,7 +49,7 @@ where async fn run( listen_address: SocketAddr, - switch_keys: &HashSet, + switch_keys: &HashSet, identity_path: &Path, identity_password: &str, ) -> Result { @@ -113,8 +113,8 @@ async fn run( tokio::select! { event = manager.read() => { let event = event?; - if let Event::Key { direction, code } = event { - if let Some(state) = key_states.get_mut(&code) { + if let Event::Key { direction, kind: KeyKind::Key(key) } = event { + if let Some(state) = key_states.get_mut(&key) { *state = if direction == Direction::Down { true } else {