read_keys

Function read_keys 

Source
pub fn read_keys() -> SmallVec<[KeyEvent; 2]>
Expand description

Reads the key press events available and saves them in an array.

This creates an independent copy of the keys, consuming the underlying buffer in the process.

Examples found in repository?
examples/keyboard.rs (line 16)
8pub extern "C" fn dosmain() -> i32 {
9    goto_xy(2, 2);
10    put_str("KEYBOARD DEMO");
11    goto_xy(0, 16);
12    put_str("ESC - quit");
13    curs_off();
14    while !shutting_down() {
15        wait_vbl();
16        let keys = read_keys();
17
18        if !keys.is_empty() {
19            goto_xy(5, 5);
20            dos_like::text_color(3);
21            put_str("!");
22            dos_like::text_color(7);
23
24            for (i, key) in keys.iter().enumerate() {
25                goto_xy(2, 8 + i as u16);
26                put_str("                  ");
27                goto_xy(2, 8 + i as u16);
28                if key.is_pressed() {
29                    put_str(format!("{:?} pressed             ", key.key_code()));
30                } else {
31                    put_str(format!("{:?} released            ", key.key_code()));
32                }
33            }
34            for i in keys.len()..8 {
35                goto_xy(2, 8 + i as u16);
36                put_str("                              ");
37            }
38        } else {
39            goto_xy(5, 5);
40            put_str(" ");
41        }
42
43        if key_state(KeyCode::KEY_ESCAPE) {
44            break;
45        }
46    }
47    0
48}