跳到主要内容

KeyboardState

搜索

Trait KeyboardState 

Source
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")

必需方法§

Source

fn add(&mut self, event_type: &EventType) -> Option<String>

如同该事件已发生一样地改变键盘状态。我们在此处并未真正调用操作系统,这在测试如果按下该键会发生什么时可能很有用。

Source

fn reset(&mut self)

将键盘状态重置为未触碰过的状态(没有 Shift、Caps Lock 等)

实现者§