pub trait KeyboardState {
// Required methods
fn add(&mut self, event_type: &EventType) -> Option<String>;
fn reset(&mut self);
}展开描述
我们可以定义一个虚拟的 Keyboard,用于检测哪种 EventType 会触发某个字符串。目前只取当前使用的键盘布局!注意:这是布局相关的。如果你的应用需要支持布局切换,请不要使用此功能!注意:Linux 上死键机制尚未实现。注意:目前仅实现了 Shift 和死键,Windows 上的 Alt + Unicode 码点输入方式无法工作。
use rdev::{Keyboard, EventType, Key, KeyboardState};
let mut keyboard = Keyboard::new().unwrap();
let string = keyboard.add(&EventType::KeyPress(Key::KeyS));
// string == Some("s")