Struct ScancodeSet1

Source
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

Source

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}

Trait Implementations§

Source§

impl Default for ScancodeSet1

Source§

fn default() -> Self

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

impl ScancodeSet for ScancodeSet1

Source§

fn advance_state(&mut self, code: u8) -> Result<Option<KeyEvent>, Error>

Implements state logic for scancode set 1

§Start:
  • E0 => Goto Extended
  • E1 => Goto Extended 2
  • < 0x80 => Key Down
  • >= 0x80 => Key Up
§Extended:
  • < 0x80 => Extended Key Down
  • >= 0x80 => Extended Key Up
§Extended 2:
  • < 0x80 => Extended 2 Key Down
  • >= 0x80 => Extended 2 Key Up

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.