1
0
Fork 0
forked from AbleOS/ableos
ableos-idl/ableos/src/keyboard/traits.rs

27 lines
967 B
Rust
Raw Normal View History

2022-04-11 17:23:11 -05:00
use super::Error;
use crate::{DecodeState, DecodedKey, HandleControl, KeyCode, KeyEvent, Modifiers};
2021-11-16 00:09:27 -06:00
pub trait ScancodeSet {
/// Handles the state logic for the decoding of scan codes into key events.
fn advance_state(&self, state: &mut DecodeState, code: u8) -> Result<Option<KeyEvent>, Error>;
2022-04-11 17:23:11 -05:00
2021-11-16 00:09:27 -06:00
/// Convert a Scan Code set X byte to our 'KeyType' enum
fn map_scancode(&self, code: u8) -> Result<KeyCode, Error>;
2022-04-11 17:23:11 -05:00
2021-11-16 00:09:27 -06:00
/// Convert a Scan Code Set X extended byte (prefixed E0) to our `KeyType`
/// enum.
fn map_extended_scancode(&self, code: u8) -> Result<KeyCode, Error>;
}
2022-04-11 17:23:11 -05:00
2021-11-16 00:09:27 -06:00
pub trait KeyboardLayout {
/// Convert a `KeyType` enum to a Unicode character, if possible.
/// `KeyType::A` maps to `Some('a')` (or `Some('A')` if shifted), while
/// `KeyType::AltLeft` returns `None`
fn map_keycode(
&self,
keycode: KeyCode,
modifiers: &Modifiers,
handle_ctrl: HandleControl,
) -> DecodedKey;
}