pub struct ScancodeSet2 { /* private fields */ }Expand description
Contains the implementation of Scancode Set 2.
See the OS dev wiki: https://wiki.osdev.org/PS/2_Keyboard#Scan_Code_Set_2 Additional reference: https://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html
Implementations§
Source§impl ScancodeSet2
impl ScancodeSet2
Sourcepub const fn new() -> ScancodeSet2
pub const fn new() -> ScancodeSet2
Construct a new ScancodeSet2 decoder.
Examples found in repository?
examples/scancodes.rs (line 30)
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}Trait Implementations§
Source§impl Default for ScancodeSet2
impl Default for ScancodeSet2
Source§impl ScancodeSet for ScancodeSet2
impl ScancodeSet for ScancodeSet2
Source§fn advance_state(&mut self, code: u8) -> Result<Option<KeyEvent>, Error>
fn advance_state(&mut self, code: u8) -> Result<Option<KeyEvent>, Error>
Implements state logic for scancode set 2
§Start:
- F0 => Goto Release
- E0 => Goto Extended
- E1 => Goto Extended2
- xx => Key Down Event
§Release:
- xxx => Key Up Event
§Extended:
- F0 => Goto Release-Extended
- xx => Extended Key Down Event
§Release-Extended:
- xxx => Extended Key Up Event
§Extended2:
- F0 => Goto Release-Extended2
- xx => Extended2 Key Down Event
§Release-Extended2:
- xxx => Extended2 Key Up Event