pub struct ScancodeSet1 { /* private fields */ }Expand description
Contains the implementation of Scancode Set 1.
See the OS dev wiki: https://wiki.osdev.org/PS/2_Keyboard#Scan_Code_Set_1
Implementations§
Source§impl ScancodeSet1
impl ScancodeSet1
Sourcepub const fn new() -> ScancodeSet1
pub const fn new() -> ScancodeSet1
Construct a new ScancodeSet1 decoder.
Examples found in repository?
examples/scancodes.rs (line 4)
3fn main() {
4 let mut s = ScancodeSet1::new();
5 // [ 0x01 ] means "Pressed Escape" in Set 1
6 match s.advance_state(0x01) {
7 Ok(Some(KeyEvent { code, state })) => {
8 println!("Scancode Set 1 0x01 is KeyCode '{code:?}' KeyState '{state:?}'");
9 }
10 Ok(None) => {
11 println!("This is wrong, we didn't think that was a complete sequence");
12 }
13 Err(e) => {
14 println!("There was an error: {e:?}");
15 }
16 }
17 // [ 0x81 ] means "Released Escape" in Set 1
18 match s.advance_state(0x81) {
19 Ok(Some(KeyEvent { code, state })) => {
20 println!("Scancode Set 1 0x81 is KeyCode '{code:?}' KeyState '{state:?}'");
21 }
22 Ok(None) => {
23 println!("This is wrong, we didn't think that was a complete sequence");
24 }
25 Err(e) => {
26 println!("There was an error: {e:?}");
27 }
28 }
29
30 let mut s = ScancodeSet2::new();
31 // [ 0x01 ] means "Pressed F9" in Set 2
32 match s.advance_state(0x01) {
33 Ok(Some(KeyEvent { code, state })) => {
34 println!("Scancode Set 2 0x01 is KeyCode '{code:?}' KeyState '{state:?}'");
35 }
36 Ok(None) => {
37 println!("This is wrong, we didn't think that was a complete sequence");
38 }
39 Err(e) => {
40 println!("There was an error: {e:?}");
41 }
42 }
43 // [ 0xF0, 0x01 ] means "Released F9" in Set 2
44 assert_eq!(Ok(None), s.advance_state(0xF0));
45 match s.advance_state(0x01) {
46 Ok(Some(KeyEvent { code, state })) => {
47 println!("Scancode Set 2 0xF0 0x01 is KeyCode '{code:?}' KeyState '{state:?}'");
48 }
49 Ok(None) => {
50 println!("This is wrong, we didn't think that was a complete sequence");
51 }
52 Err(e) => {
53 println!("There was an error: {e:?}");
54 }
55 }
56}