Map keyboard to bépo
This commit is contained in:
340
src/keymap.rs
340
src/keymap.rs
@@ -1,64 +1,296 @@
|
||||
use crate::KeyboardState;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive_const(PartialEq, Eq)]
|
||||
pub enum ModifierType {
|
||||
Shift,
|
||||
Alt,
|
||||
AltGr,
|
||||
Control,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive_const(PartialEq, Eq)]
|
||||
pub enum KeyType {
|
||||
Ascii(char),
|
||||
// Special, // F1, Home, etc.
|
||||
Modifier, // Shift, Ctrl
|
||||
Modifier(ModifierType),
|
||||
Unknown,
|
||||
}
|
||||
|
||||
pub const fn map_keycode(code: u16, shift: bool) -> KeyType {
|
||||
match code {
|
||||
// Numbers row
|
||||
2..=11 => {
|
||||
let val = if shift {
|
||||
[')', '!', '@', '#', '$', '%', '^', '&', '*', '('][(code - 2) as usize]
|
||||
} else {
|
||||
(code as u8 - 2 + b'1') as char
|
||||
};
|
||||
if code == 11 && !shift {
|
||||
KeyType::Ascii('0')
|
||||
} else {
|
||||
KeyType::Ascii(val)
|
||||
}
|
||||
}
|
||||
|
||||
// Letters (Simplified QWERTY)
|
||||
16 => KeyType::Ascii(if shift { 'Q' } else { 'q' }),
|
||||
17 => KeyType::Ascii(if shift { 'W' } else { 'w' }),
|
||||
18 => KeyType::Ascii(if shift { 'E' } else { 'e' }),
|
||||
19 => KeyType::Ascii(if shift { 'R' } else { 'r' }),
|
||||
20 => KeyType::Ascii(if shift { 'T' } else { 't' }),
|
||||
21 => KeyType::Ascii(if shift { 'Y' } else { 'y' }),
|
||||
22 => KeyType::Ascii(if shift { 'U' } else { 'u' }),
|
||||
23 => KeyType::Ascii(if shift { 'I' } else { 'i' }),
|
||||
24 => KeyType::Ascii(if shift { 'O' } else { 'o' }),
|
||||
25 => KeyType::Ascii(if shift { 'P' } else { 'p' }),
|
||||
30 => KeyType::Ascii(if shift { 'A' } else { 'a' }),
|
||||
31 => KeyType::Ascii(if shift { 'S' } else { 's' }),
|
||||
32 => KeyType::Ascii(if shift { 'D' } else { 'd' }),
|
||||
33 => KeyType::Ascii(if shift { 'F' } else { 'f' }),
|
||||
34 => KeyType::Ascii(if shift { 'G' } else { 'g' }),
|
||||
35 => KeyType::Ascii(if shift { 'H' } else { 'h' }),
|
||||
36 => KeyType::Ascii(if shift { 'J' } else { 'j' }),
|
||||
37 => KeyType::Ascii(if shift { 'K' } else { 'k' }),
|
||||
38 => KeyType::Ascii(if shift { 'L' } else { 'l' }),
|
||||
44 => KeyType::Ascii(if shift { 'Z' } else { 'z' }),
|
||||
45 => KeyType::Ascii(if shift { 'X' } else { 'x' }),
|
||||
46 => KeyType::Ascii(if shift { 'C' } else { 'c' }),
|
||||
47 => KeyType::Ascii(if shift { 'V' } else { 'v' }),
|
||||
48 => KeyType::Ascii(if shift { 'B' } else { 'b' }),
|
||||
49 => KeyType::Ascii(if shift { 'N' } else { 'n' }),
|
||||
50 => KeyType::Ascii(if shift { 'M' } else { 'm' }),
|
||||
|
||||
// Control
|
||||
28 => KeyType::Ascii('\n'),
|
||||
57 => KeyType::Ascii(' '),
|
||||
14 => KeyType::Ascii('\x08'), // Backspace
|
||||
1 => KeyType::Ascii('\x1b'), // Escape
|
||||
|
||||
// Modifiers
|
||||
42 | 54 => KeyType::Modifier, // LShift, RShift
|
||||
29 | 97 => KeyType::Modifier, // LCtrl, RCtrl
|
||||
pub const fn map_keycode(code: u16, state: &KeyboardState) -> KeyType {
|
||||
let res = match code {
|
||||
KEY_BACKSPACE => KeyType::Ascii('\x08'),
|
||||
KEY_ESCAPE => KeyType::Ascii('\x1b'),
|
||||
KEY_TAB => KeyType::Ascii('\t'),
|
||||
KEY_ENTER => KeyType::Ascii('\n'),
|
||||
KEY_SPACE => KeyType::Ascii(' '),
|
||||
KEY_LEFTSHIFT | KEY_RIGHTSHIFT => KeyType::Modifier(ModifierType::Shift),
|
||||
KEY_LEFTCTRL => KeyType::Modifier(ModifierType::Control),
|
||||
KEY_LEFTALT => KeyType::Modifier(ModifierType::Alt),
|
||||
KEY_RIGHTALT => KeyType::Modifier(ModifierType::AltGr),
|
||||
|
||||
_ => KeyType::Unknown,
|
||||
};
|
||||
if res != KeyType::Unknown {
|
||||
return res;
|
||||
}
|
||||
|
||||
if state.shift_modifier {
|
||||
match code {
|
||||
KEY_1 => KeyType::Ascii('1'),
|
||||
KEY_2 => KeyType::Ascii('2'),
|
||||
KEY_3 => KeyType::Ascii('3'),
|
||||
KEY_4 => KeyType::Ascii('4'),
|
||||
KEY_5 => KeyType::Ascii('5'),
|
||||
KEY_6 => KeyType::Ascii('6'),
|
||||
KEY_7 => KeyType::Ascii('7'),
|
||||
KEY_8 => KeyType::Ascii('8'),
|
||||
KEY_9 => KeyType::Ascii('9'),
|
||||
KEY_0 => KeyType::Ascii('0'),
|
||||
KEY_MINUS => KeyType::Ascii('°'),
|
||||
KEY_EQUAL => KeyType::Ascii('`'),
|
||||
|
||||
KEY_Q => KeyType::Ascii('B'),
|
||||
KEY_W => KeyType::Ascii('É'),
|
||||
KEY_E => KeyType::Ascii('P'),
|
||||
KEY_R => KeyType::Ascii('O'),
|
||||
KEY_T => KeyType::Ascii('È'),
|
||||
KEY_Y => KeyType::Ascii('!'),
|
||||
KEY_U => KeyType::Ascii('V'),
|
||||
KEY_I => KeyType::Ascii('D'),
|
||||
KEY_O => KeyType::Ascii('L'),
|
||||
KEY_P => KeyType::Ascii('J'),
|
||||
KEY_A => KeyType::Ascii('A'),
|
||||
KEY_S => KeyType::Ascii('U'),
|
||||
KEY_D => KeyType::Ascii('I'),
|
||||
KEY_F => KeyType::Ascii('E'),
|
||||
KEY_G => KeyType::Ascii(';'),
|
||||
KEY_H => KeyType::Ascii('C'),
|
||||
KEY_J => KeyType::Ascii('T'),
|
||||
KEY_K => KeyType::Ascii('S'),
|
||||
KEY_L => KeyType::Ascii('R'),
|
||||
KEY_Z => KeyType::Ascii('À'),
|
||||
KEY_X => KeyType::Ascii('Y'),
|
||||
KEY_C => KeyType::Ascii('X'),
|
||||
KEY_V => KeyType::Ascii(':'),
|
||||
KEY_B => KeyType::Ascii('K'),
|
||||
KEY_N => KeyType::Ascii('?'),
|
||||
KEY_M => KeyType::Ascii('Q'),
|
||||
|
||||
KEY_LEFTBRACE => KeyType::Ascii('Z'),
|
||||
KEY_RIGHTBRACE => KeyType::Ascii('W'),
|
||||
KEY_BACKSLASH => KeyType::Ascii('Ç'),
|
||||
|
||||
KEY_SEMICOLON => KeyType::Ascii('N'),
|
||||
KEY_APOSTROPHE => KeyType::Ascii('M'),
|
||||
|
||||
KEY_COMMA => KeyType::Ascii('G'),
|
||||
KEY_DOT => KeyType::Ascii('H'),
|
||||
KEY_SLASH => KeyType::Ascii('F'),
|
||||
|
||||
_ => KeyType::Unknown,
|
||||
}
|
||||
} else {
|
||||
if state.alt_gr_modifier {
|
||||
match code {
|
||||
// KEY_1 => KeyType::Ascii('—'),
|
||||
KEY_2 => KeyType::Ascii('<'),
|
||||
KEY_3 => KeyType::Ascii('>'),
|
||||
KEY_4 => KeyType::Ascii('['),
|
||||
KEY_5 => KeyType::Ascii(']'),
|
||||
KEY_6 => KeyType::Ascii('^'),
|
||||
KEY_7 => KeyType::Ascii('±'),
|
||||
// KEY_8 => KeyType::Ascii('−'),
|
||||
KEY_9 => KeyType::Ascii('÷'),
|
||||
KEY_0 => KeyType::Ascii('×'),
|
||||
// KEY_MINUS => KeyType::Ascii('≠'),
|
||||
// KEY_EQUAL => KeyType::Ascii('‰'),
|
||||
KEY_Q => KeyType::Ascii('|'),
|
||||
// KEY_W => KeyType::Ascii(''),
|
||||
KEY_E => KeyType::Ascii('&'),
|
||||
KEY_R => KeyType::Ascii('œ'),
|
||||
// KEY_T => KeyType::Ascii(''),
|
||||
KEY_Y => KeyType::Ascii('¡'),
|
||||
// KEY_U => KeyType::Ascii(''),
|
||||
KEY_I => KeyType::Ascii('ð'),
|
||||
// KEY_O => KeyType::Ascii(''),
|
||||
KEY_P => KeyType::Ascii('ij'),
|
||||
KEY_A => KeyType::Ascii('æ'),
|
||||
KEY_S => KeyType::Ascii('ù'),
|
||||
// KEY_D => KeyType::Ascii(''),
|
||||
// KEY_F => KeyType::Ascii('€'),
|
||||
// KEY_G => KeyType::Ascii('’'),
|
||||
KEY_H => KeyType::Ascii('©'),
|
||||
KEY_J => KeyType::Ascii('þ'),
|
||||
KEY_K => KeyType::Ascii('ß'),
|
||||
KEY_L => KeyType::Ascii('®'),
|
||||
KEY_Z => KeyType::Ascii('\\'),
|
||||
KEY_X => KeyType::Ascii('{'),
|
||||
KEY_C => KeyType::Ascii('}'),
|
||||
// KEY_V => KeyType::Ascii('…'),
|
||||
KEY_B => KeyType::Ascii('~'),
|
||||
KEY_N => KeyType::Ascii('¿'),
|
||||
// KEY_M => KeyType::Ascii(''),
|
||||
KEY_LEFTBRACE => KeyType::Ascii('ə'),
|
||||
// KEY_RIGHTBRACE => KeyType::Ascii(''),
|
||||
// KEY_SEMICOLON => KeyType::Ascii(''),
|
||||
// KEY_APOSTROPHE => KeyType::Ascii(''),
|
||||
// KEY_COMMA => KeyType::Ascii(''),
|
||||
// KEY_DOT => KeyType::Ascii('†'),
|
||||
// KEY_SLASH => KeyType::Ascii(''),
|
||||
_ => KeyType::Unknown,
|
||||
}
|
||||
} else {
|
||||
match code {
|
||||
KEY_1 => KeyType::Ascii('"'),
|
||||
KEY_2 => KeyType::Ascii('«'),
|
||||
KEY_3 => KeyType::Ascii('»'),
|
||||
KEY_4 => KeyType::Ascii('('),
|
||||
KEY_5 => KeyType::Ascii(')'),
|
||||
KEY_6 => KeyType::Ascii('@'),
|
||||
KEY_7 => KeyType::Ascii('+'),
|
||||
KEY_8 => KeyType::Ascii('-'),
|
||||
KEY_9 => KeyType::Ascii('/'),
|
||||
KEY_0 => KeyType::Ascii('*'),
|
||||
KEY_MINUS => KeyType::Ascii('='),
|
||||
KEY_EQUAL => KeyType::Ascii('%'),
|
||||
|
||||
KEY_Q => KeyType::Ascii('b'),
|
||||
KEY_W => KeyType::Ascii('é'),
|
||||
KEY_E => KeyType::Ascii('p'),
|
||||
KEY_R => KeyType::Ascii('o'),
|
||||
KEY_T => KeyType::Ascii('è'),
|
||||
KEY_Y => KeyType::Ascii('^'),
|
||||
KEY_U => KeyType::Ascii('v'),
|
||||
KEY_I => KeyType::Ascii('d'),
|
||||
KEY_O => KeyType::Ascii('l'),
|
||||
KEY_P => KeyType::Ascii('j'),
|
||||
KEY_A => KeyType::Ascii('a'),
|
||||
KEY_S => KeyType::Ascii('u'),
|
||||
KEY_D => KeyType::Ascii('i'),
|
||||
KEY_F => KeyType::Ascii('e'),
|
||||
KEY_G => KeyType::Ascii(','),
|
||||
KEY_H => KeyType::Ascii('c'),
|
||||
KEY_J => KeyType::Ascii('t'),
|
||||
KEY_K => KeyType::Ascii('s'),
|
||||
KEY_L => KeyType::Ascii('r'),
|
||||
KEY_Z => KeyType::Ascii('à'),
|
||||
KEY_X => KeyType::Ascii('y'),
|
||||
KEY_C => KeyType::Ascii('x'),
|
||||
KEY_V => KeyType::Ascii('.'),
|
||||
KEY_B => KeyType::Ascii('k'),
|
||||
KEY_N => KeyType::Ascii('\''),
|
||||
KEY_M => KeyType::Ascii('q'),
|
||||
|
||||
KEY_LEFTBRACE => KeyType::Ascii('z'),
|
||||
KEY_RIGHTBRACE => KeyType::Ascii('w'),
|
||||
KEY_BACKSLASH => KeyType::Ascii('ç'),
|
||||
|
||||
KEY_SEMICOLON => KeyType::Ascii('n'),
|
||||
KEY_APOSTROPHE => KeyType::Ascii('m'),
|
||||
|
||||
KEY_COMMA => KeyType::Ascii('g'),
|
||||
KEY_DOT => KeyType::Ascii('h'),
|
||||
KEY_SLASH => KeyType::Ascii('f'),
|
||||
|
||||
_ => KeyType::Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pub const KEY_RESERVED: u16 = 0;
|
||||
pub const KEY_ESCAPE: u16 = 1;
|
||||
|
||||
pub const KEY_1: u16 = 2;
|
||||
pub const KEY_2: u16 = 3;
|
||||
pub const KEY_3: u16 = 4;
|
||||
pub const KEY_4: u16 = 5;
|
||||
pub const KEY_5: u16 = 6;
|
||||
pub const KEY_6: u16 = 7;
|
||||
pub const KEY_7: u16 = 8;
|
||||
pub const KEY_8: u16 = 9;
|
||||
pub const KEY_9: u16 = 10;
|
||||
pub const KEY_0: u16 = 11;
|
||||
pub const KEY_MINUS: u16 = 12;
|
||||
pub const KEY_EQUAL: u16 = 13;
|
||||
pub const KEY_BACKSPACE: u16 = 14;
|
||||
|
||||
pub const KEY_TAB: u16 = 15;
|
||||
|
||||
pub const KEY_Q: u16 = 16;
|
||||
pub const KEY_W: u16 = 17;
|
||||
pub const KEY_E: u16 = 18;
|
||||
pub const KEY_R: u16 = 19;
|
||||
pub const KEY_T: u16 = 20;
|
||||
pub const KEY_Y: u16 = 21;
|
||||
pub const KEY_U: u16 = 22;
|
||||
pub const KEY_I: u16 = 23;
|
||||
pub const KEY_O: u16 = 24;
|
||||
pub const KEY_P: u16 = 25;
|
||||
|
||||
pub const KEY_LEFTBRACE: u16 = 26;
|
||||
pub const KEY_RIGHTBRACE: u16 = 27;
|
||||
|
||||
pub const KEY_ENTER: u16 = 28;
|
||||
pub const KEY_LEFTCTRL: u16 = 29;
|
||||
|
||||
pub const KEY_A: u16 = 30;
|
||||
pub const KEY_S: u16 = 31;
|
||||
pub const KEY_D: u16 = 32;
|
||||
pub const KEY_F: u16 = 33;
|
||||
pub const KEY_G: u16 = 34;
|
||||
pub const KEY_H: u16 = 35;
|
||||
pub const KEY_J: u16 = 36;
|
||||
pub const KEY_K: u16 = 37;
|
||||
pub const KEY_L: u16 = 38;
|
||||
|
||||
pub const KEY_SEMICOLON: u16 = 39;
|
||||
pub const KEY_APOSTROPHE: u16 = 40;
|
||||
// pub const KEY_GRAVE: u16 = 41;
|
||||
|
||||
pub const KEY_LEFTSHIFT: u16 = 42;
|
||||
pub const KEY_BACKSLASH: u16 = 43;
|
||||
pub const KEY_Z: u16 = 44;
|
||||
pub const KEY_X: u16 = 45;
|
||||
pub const KEY_C: u16 = 46;
|
||||
pub const KEY_V: u16 = 47;
|
||||
pub const KEY_B: u16 = 48;
|
||||
pub const KEY_N: u16 = 49;
|
||||
pub const KEY_M: u16 = 50;
|
||||
pub const KEY_COMMA: u16 = 51;
|
||||
pub const KEY_DOT: u16 = 52;
|
||||
pub const KEY_SLASH: u16 = 53;
|
||||
|
||||
pub const KEY_RIGHTSHIFT: u16 = 54;
|
||||
pub const KEY_LEFTALT: u16 = 56;
|
||||
pub const KEY_SPACE: u16 = 57;
|
||||
// pub const KEY_CAPSLOCK: u16 = 58;
|
||||
|
||||
// pub const KEY_F1: u16 = 59;
|
||||
// pub const KEY_F2: u16 = 60;
|
||||
// pub const KEY_F3: u16 = 61;
|
||||
// pub const KEY_F4: u16 = 62;
|
||||
// pub const KEY_F5: u16 = 63;
|
||||
// pub const KEY_F6: u16 = 64;
|
||||
// pub const KEY_F7: u16 = 65;
|
||||
// pub const KEY_F8: u16 = 66;
|
||||
// pub const KEY_F9: u16 = 67;
|
||||
// pub const KEY_F10: u16 = 68;
|
||||
|
||||
pub const KEY_RIGHTALT: u16 = 100;
|
||||
// pub const KEY_HOME: u16 = 102;
|
||||
// pub const KEY_UP: u16 = 103;
|
||||
// pub const KEY_PAGEUP: u16 = 104;
|
||||
// pub const KEY_LEFT: u16 = 105;
|
||||
// pub const KEY_RIGHT: u16 = 106;
|
||||
// pub const KEY_END: u16 = 107;
|
||||
// pub const KEY_DOWN: u16 = 108;
|
||||
// pub const KEY_PAGEDOWN: u16 = 109;
|
||||
// pub const KEY_INSERT: u16 = 110;
|
||||
// pub const KEY_DELETE: u16 = 111;
|
||||
|
||||
// pub const KEY_MUTE: u16 = 113;
|
||||
// pub const KEY_VOLUMEDOWN: u16 = 114;
|
||||
// pub const KEY_VOLUMEUP: u16 = 115;
|
||||
|
||||
Reference in New Issue
Block a user