pub struct KeyEventConverter { /* private fields */ }Available on crate feature
keyboard-types only.Expand description
Stateful translator from XComponent key events to
keyboard_types::KeyboardEvent.
The state tracks which key codes are down (to derive repeat) and the Meta
keys (used when ModifierState::meta is None). Feed it every key event
of one physical keyboard, in order, and reset it with
clear on focus loss. Returns None for an unknown key
action.
Note: this stateful helper logically belongs in a safe XComponent wrapper crate and will move there when such an abstraction crate is created; it lives here until then.
use keyboard_types::{Code, Key};
use xcomponent_sys::keyboard_types_compat::{KeyEventConverter, ModifierState};
use xcomponent_sys::{OH_NativeXComponent_KeyAction, OH_NativeXComponent_KeyCode};
let mut converter = KeyEventConverter::new();
let shifted = ModifierState {
shift: true,
..Default::default()
};
let event = converter
.convert(
OH_NativeXComponent_KeyAction::OH_NATIVEXCOMPONENT_KEY_ACTION_DOWN,
OH_NativeXComponent_KeyCode::KEY_A,
shifted,
)
.unwrap();
assert_eq!(event.key, Key::Character("A".to_string()));
assert_eq!(event.code, Code::KeyA);Implementations§
Source§impl KeyEventConverter
impl KeyEventConverter
pub const fn new() -> Self
pub fn convert( &mut self, action: OH_NativeXComponent_KeyAction, key_code: OH_NativeXComponent_KeyCode, modifiers: ModifierState, ) -> Option<KeyboardEvent>
Trait Implementations§
Source§impl Clone for KeyEventConverter
impl Clone for KeyEventConverter
Source§fn clone(&self) -> KeyEventConverter
fn clone(&self) -> KeyEventConverter
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for KeyEventConverter
impl Debug for KeyEventConverter
Source§impl Default for KeyEventConverter
impl Default for KeyEventConverter
Source§fn default() -> KeyEventConverter
fn default() -> KeyEventConverter
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for KeyEventConverter
impl RefUnwindSafe for KeyEventConverter
impl Send for KeyEventConverter
impl Sync for KeyEventConverter
impl Unpin for KeyEventConverter
impl UnsafeUnpin for KeyEventConverter
impl UnwindSafe for KeyEventConverter
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