Struct pc_keyboard::Keyboard

source ·
pub struct Keyboard<L, S>{ /* private fields */ }
Expand description

Encapsulates decode/sampling logic, and handles state transitions and key events.

Implementations§

source§

impl<L, S> Keyboard<L, S>

source

pub const fn new( scancode_set: S, layout: L, handle_ctrl: HandleControl, ) -> Keyboard<L, S>

Make a new Keyboard object with the given layout.

source

pub fn set_ctrl_handling(&mut self, new_value: HandleControl)

Change the Ctrl key mapping.

source

pub const fn get_ctrl_handling(&self) -> HandleControl

Get the current Ctrl key mapping.

source

pub fn clear(&mut self)

Clears the bit register.

Call this when there is a timeout reading data from the keyboard.

source

pub fn add_word(&mut self, word: u16) -> Result<Option<KeyEvent>, Error>

Processes a 16-bit word from the keyboard.

  • The start bit (0) must be in bit 0.
  • The data octet must be in bits 1..8, with the LSB in bit 1 and the MSB in bit 8.
  • The parity bit must be in bit 9.
  • The stop bit (1) must be in bit 10.
source

pub fn add_byte(&mut self, byte: u8) -> Result<Option<KeyEvent>, Error>

Processes an 8-bit byte from the keyboard.

We assume the start, stop and parity bits have been processed and verified.

source

pub fn add_bit(&mut self, bit: bool) -> Result<Option<KeyEvent>, Error>

Shift a bit into the register.

Call this /or/ call add_word - don’t call both. Until the last bit is added you get Ok(None) returned.

source

pub fn process_keyevent(&mut self, ev: KeyEvent) -> Option<DecodedKey>

Processes a KeyEvent returned from add_bit, add_byte or add_word and produces a decoded key.

For example, the KeyEvent for pressing the ‘5’ key on your keyboard gives a DecodedKey of unicode character ‘5’, unless the shift key is held in which case you get the unicode character ‘%’.

Trait Implementations§

source§

impl<L, S> Debug for Keyboard<L, S>
where S: ScancodeSet + Debug, L: KeyboardLayout + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<L, S> Freeze for Keyboard<L, S>
where S: Freeze, L: Freeze,

§

impl<L, S> RefUnwindSafe for Keyboard<L, S>
where S: RefUnwindSafe, L: RefUnwindSafe,

§

impl<L, S> Send for Keyboard<L, S>
where S: Send, L: Send,

§

impl<L, S> Sync for Keyboard<L, S>
where S: Sync, L: Sync,

§

impl<L, S> Unpin for Keyboard<L, S>
where S: Unpin, L: Unpin,

§

impl<L, S> UnwindSafe for Keyboard<L, S>
where S: UnwindSafe, L: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.