1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use pc_keyboard::{
    layouts::{AnyLayout, Uk105Key},
    DecodedKey, EventDecoder, KeyCode, KeyEvent, KeyState,
};

fn main() {
    let mut decoder = EventDecoder::new(
        AnyLayout::Uk105Key(Uk105Key),
        pc_keyboard::HandleControl::Ignore,
    );

    // User presses 'A' on their UK keyboard, gets a lower-case 'a'.
    let decoded_key = decoder.process_keyevent(KeyEvent {
        code: KeyCode::A,
        state: KeyState::Down,
    });
    assert_eq!(Some(DecodedKey::Unicode('a')), decoded_key);
    println!("Got {:?}", decoded_key);

    // User releases 'A' on their UK keyboard
    let decoded_key = decoder.process_keyevent(KeyEvent {
        code: KeyCode::A,
        state: KeyState::Up,
    });
    assert_eq!(None, decoded_key);

    // User presses 'Shift' on their UK keyboard
    let decoded_key = decoder.process_keyevent(KeyEvent {
        code: KeyCode::LShift,
        state: KeyState::Down,
    });
    assert_eq!(None, decoded_key);

    // User presses 'A' on their UK keyboard, now gets a Capital A
    let decoded_key = decoder.process_keyevent(KeyEvent {
        code: KeyCode::A,
        state: KeyState::Down,
    });
    assert_eq!(Some(DecodedKey::Unicode('A')), decoded_key);
    println!("Got {:?}", decoded_key);

    // User releases 'A' on their UK keyboard
    let decoded_key = decoder.process_keyevent(KeyEvent {
        code: KeyCode::A,
        state: KeyState::Up,
    });
    assert_eq!(None, decoded_key);

    // User releases 'Shift' on their UK keyboard
    let decoded_key = decoder.process_keyevent(KeyEvent {
        code: KeyCode::LShift,
        state: KeyState::Up,
    });
    assert_eq!(None, decoded_key);
}