Struct pc_keyboard::ScancodeSet2

source ·
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

source

pub const fn new() -> ScancodeSet2

Construct a new ScancodeSet2 decoder.

Examples found in repository?
examples/scancodes.rs (line 30)
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
56
fn main() {
    let mut s = ScancodeSet1::new();
    // [ 0x01 ] means "Pressed Escape" in Set 1
    match s.advance_state(0x01) {
        Ok(Some(KeyEvent { code, state })) => {
            println!("Scancode Set 1 0x01 is KeyCode '{code:?}' KeyState '{state:?}'");
        }
        Ok(None) => {
            println!("This is wrong, we didn't think that was a complete sequence");
        }
        Err(e) => {
            println!("There was an error: {e:?}");
        }
    }
    // [ 0x81 ] means "Released Escape" in Set 1
    match s.advance_state(0x81) {
        Ok(Some(KeyEvent { code, state })) => {
            println!("Scancode Set 1 0x81 is KeyCode '{code:?}' KeyState '{state:?}'");
        }
        Ok(None) => {
            println!("This is wrong, we didn't think that was a complete sequence");
        }
        Err(e) => {
            println!("There was an error: {e:?}");
        }
    }

    let mut s = ScancodeSet2::new();
    // [ 0x01 ] means "Pressed F9" in Set 2
    match s.advance_state(0x01) {
        Ok(Some(KeyEvent { code, state })) => {
            println!("Scancode Set 2 0x01 is KeyCode '{code:?}' KeyState '{state:?}'");
        }
        Ok(None) => {
            println!("This is wrong, we didn't think that was a complete sequence");
        }
        Err(e) => {
            println!("There was an error: {e:?}");
        }
    }
    // [ 0xF0, 0x01 ] means "Released F9" in Set 2
    assert_eq!(Ok(None), s.advance_state(0xF0));
    match s.advance_state(0x01) {
        Ok(Some(KeyEvent { code, state })) => {
            println!("Scancode Set 2 0xF0 0x01 is KeyCode '{code:?}' KeyState '{state:?}'");
        }
        Ok(None) => {
            println!("This is wrong, we didn't think that was a complete sequence");
        }
        Err(e) => {
            println!("There was an error: {e:?}");
        }
    }
}

Trait Implementations§

source§

impl Default for ScancodeSet2

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl ScancodeSet for ScancodeSet2

source§

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.