code_scanner_driver/keyboard/
keymap.rs

1use rdev::Key;
2
3pub fn key_to_char(k: Key, hint: Option<&str>) -> Option<char> {
4    if let Some(h) = hint {
5        if h.len() == 1 {
6            return h.chars().next();
7        }
8    }
9
10    use Key::*;
11    Some(match k {
12        Num0 => '0', Num1 => '1', Num2 => '2', Num3 => '3', Num4 => '4',
13        Num5 => '5', Num6 => '6', Num7 => '7', Num8 => '8', Num9 => '9',
14
15        KeyA => 'a', KeyB => 'b', KeyC => 'c', KeyD => 'd', KeyE => 'e',
16        KeyF => 'f', KeyG => 'g', KeyH => 'h', KeyI => 'i', KeyJ => 'j',
17        KeyK => 'k', KeyL => 'l', KeyM => 'm', KeyN => 'n', KeyO => 'o',
18        KeyP => 'p', KeyQ => 'q', KeyR => 'r', KeyS => 's', KeyT => 't',
19        KeyU => 'u', KeyV => 'v', KeyW => 'w', KeyX => 'x', KeyY => 'y',
20        KeyZ => 'z',
21
22        Space => ' ',
23        Minus => '-',
24        Equal => '=',
25        Comma => ',',
26        Dot => '.',
27        Slash => '/',
28        BackSlash => '\\',
29
30        _ => return None,
31    })
32}