pub trait KeyboardState {
// Required method
fn add(&mut self, event_type: &EventType) -> Option<UnicodeInfo>;
}Expand description
We can define a dummy Keyboard, that we will use to detect what kind of EventType trigger some String. We get the currently used layout for now ! Caveat : This is layout dependent. If your app needs to support layout switching don’t use this ! Caveat: On Linux, the dead keys mechanism is not implemented. Caveat: Only shift and dead keys are implemented, Alt+unicode code on windows won’t work.
use rdev::{Keyboard, EventType, Key, KeyboardState};
let mut keyboard = Keyboard::new().unwrap();
let string = keyboard.add(&EventType::KeyPress(Key::KeyS)).unwrap().name.unwrap();
// string == Some("s")Required Methods§
Sourcefn add(&mut self, event_type: &EventType) -> Option<UnicodeInfo>
fn add(&mut self, event_type: &EventType) -> Option<UnicodeInfo>
Changes the keyboard state as if this event happened. we don’t really hit the OS here, which might come handy to test what should happen if we were to hit said key.