Struct pc_keyboard::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
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)
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 ScancodeSet1
impl Default for ScancodeSet1
source§impl ScancodeSet for ScancodeSet1
impl ScancodeSet for ScancodeSet1
Auto Trait Implementations§
impl Freeze for ScancodeSet1
impl RefUnwindSafe for ScancodeSet1
impl Send for ScancodeSet1
impl Sync for ScancodeSet1
impl Unpin for ScancodeSet1
impl UnwindSafe for ScancodeSet1
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more