Update key codes to be somewhat similar to deprecated web API

This commit is contained in:
Mark McCaskey 2019-12-10 11:14:59 -08:00
parent 5da98caf83
commit 2dcb37b4be

View File

@ -59,16 +59,40 @@ pub fn bytes_for_input_event(input_event: InputEvent) -> (u8, [u8; 8], usize) {
pub fn map_key_to_bytes(key: Key) -> u8 {
match key {
Key::Key0 => b'0',
Key::Key1 => b'1',
Key::Key2 => b'2',
Key::Key3 => b'3',
Key::Key4 => b'4',
Key::Key5 => b'5',
Key::Key6 => b'6',
Key::Key7 => b'7',
Key::Key8 => b'8',
Key::Key9 => b'9',
Key::Backspace => 8,
Key::Tab => 9,
Key::NumPadEnter | Key::Enter => 13,
Key::LeftShift | Key::RightShift => 16,
Key::LeftCtrl | Key::RightCtrl => 17,
Key::LeftAlt | Key::RightAlt => 18,
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::Left => 37,
Key::Up => 38,
Key::Right => 39,
Key::Down => 40,
Key::Insert => 45,
Key::Delete => 46,
Key::Key0 => 48,
Key::Key1 => 49,
Key::Key2 => 50,
Key::Key3 => 51,
Key::Key4 => 52,
Key::Key5 => 53,
Key::Key6 => 54,
Key::Key7 => 55,
Key::Key8 => 56,
Key::Key9 => 57,
Key::A => b'A',
Key::B => b'B',
Key::C => b'C',
@ -95,86 +119,54 @@ pub fn map_key_to_bytes(key: Key) -> u8 {
Key::X => b'X',
Key::Y => b'Y',
Key::Z => b'Z',
Key::F1 => 131,
Key::F2 => 132,
Key::F3 => 133,
Key::F4 => 134,
Key::F5 => 135,
Key::F6 => 136,
Key::F7 => 137,
Key::F8 => 138,
Key::F9 => 139,
Key::F10 => 140,
Key::F11 => 141,
Key::F12 => 142,
Key::F13 => 143,
Key::F14 => 144,
Key::F15 => 145,
Key::Down => 146,
Key::Left => 147,
Key::Right => 148,
Key::Up => 149,
Key::Apostrophe => b'\'',
Key::Backquote => b'`',
Key::LeftSuper => 91,
Key::RightSuper => 92,
Key::Backslash => b'\\',
Key::Comma => b',',
Key::Equal => b'=',
Key::LeftBracket => b'[',
Key::Minus => b'-',
Key::Period => b'.',
Key::RightBracket => b']',
Key::Semicolon => b';',
Key::NumPad0 => 96,
Key::NumPad1 => 97,
Key::NumPad2 => 98,
Key::NumPad3 => 99,
Key::NumPad4 => 100,
Key::NumPad5 => 101,
Key::NumPad6 => 102,
Key::NumPad7 => 103,
Key::NumPad8 => 104,
Key::NumPad9 => 105,
Key::NumPadAsterisk => 106,
Key::NumPadPlus => 107,
Key::NumPadMinus => 109,
Key::NumPadDot => 110,
Key::NumPadSlash => 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::Slash => b'/',
Key::Backspace => 128,
Key::Delete => 127,
Key::End => 150,
Key::Enter => b'\n',
Key::NumLock => 144,
Key::ScrollLock => 145,
Key::Semicolon => 186,
Key::Equal => 187,
Key::Comma => 188,
Key::Minus => 189,
Key::Period => 190,
Key::Slash => 191,
Key::Backquote => 192,
Key::Backslash => 220,
Key::Apostrophe => 220,
Key::Escape => 28,
Key::Home => 151,
Key::Insert => 152,
Key::Menu => 153,
Key::PageDown => 154,
Key::PageUp => 155,
Key::Pause => 156,
Key::Space => b' ',
Key::Tab => b'\t',
Key::NumLock => 157,
Key::CapsLock => 158,
Key::ScrollLock => 159,
Key::LeftShift => 160,
Key::RightShift => 161,
Key::LeftCtrl => 162,
Key::RightCtrl => 163,
Key::NumPad0 => 170,
Key::NumPad1 => 171,
Key::NumPad2 => 172,
Key::NumPad3 => 173,
Key::NumPad4 => 174,
Key::NumPad5 => 175,
Key::NumPad6 => 176,
Key::NumPad7 => 177,
Key::NumPad8 => 178,
Key::NumPad9 => 179,
Key::NumPadDot => 180,
Key::NumPadSlash => 181,
Key::NumPadAsterisk => 182,
Key::NumPadMinus => 183,
Key::NumPadPlus => 184,
Key::NumPadEnter => 185,
Key::LeftAlt => 186,
Key::RightAlt => 187,
Key::LeftSuper => 188,
Key::RightSuper => 189,
Key::LeftBracket => 219,
Key::RightBracket => 221,
_ => 255,
}