MCPcopy Create free account
hub / github.com/emberian/evdev / main

Function main

examples/virtual_keyboard.rs:9–43  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7use std::time::Duration;
8
9fn main() -> std::io::Result<()> {
10 let mut keys = AttributeSet::<KeyCode>::new();
11 keys.insert(KeyCode::BTN_DPAD_UP);
12
13 let mut device = VirtualDevice::builder()?
14 .name("Fake Keyboard")
15 .with_keys(&keys)?
16 .build()
17 .unwrap();
18
19 for path in device.enumerate_dev_nodes_blocking()? {
20 let path = path?;
21 println!("Available as {}", path.display());
22 }
23
24 // Note this will ACTUALLY PRESS the button on your computer.
25 // Hopefully you don't have BTN_DPAD_UP bound to anything important.
26 let code = KeyCode::BTN_DPAD_UP.code();
27
28 println!("Waiting for Ctrl-C...");
29 loop {
30 // this guarantees a key event
31 let down_event = *KeyEvent::new(KeyCode(code), 1);
32 device.emit(&[down_event]).unwrap();
33 println!("Pressed.");
34 sleep(Duration::from_secs(2));
35
36 // alternativeley we can create a InputEvent, which will be any variant of InputEvent
37 // depending on the type_ value
38 let up_event = InputEvent::new(EventType::KEY.0, code, 0);
39 device.emit(&[up_event]).unwrap();
40 println!("Released.");
41 sleep(Duration::from_secs(2));
42 }
43}

Callers

nothing calls this directly

Calls 8

KeyCodeClass · 0.85
insertMethod · 0.80
buildMethod · 0.80
with_keysMethod · 0.80
emitMethod · 0.80
nameMethod · 0.45
codeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…