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

Function main

examples/virtual_joystick.rs:8–38  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6use std::time::Duration;
7
8fn main() -> std::io::Result<()> {
9 let abs_setup = AbsInfo::new(256, 0, 512, 20, 20, 1);
10 let abs_x = UinputAbsSetup::new(AbsoluteAxisCode::ABS_X, abs_setup);
11
12 let mut device = VirtualDevice::builder()?
13 .name("Fake Joystick")
14 .with_absolute_axis(&abs_x)?
15 .build()
16 .unwrap();
17
18 for path in device.enumerate_dev_nodes_blocking()? {
19 let path = path?;
20 println!("Available as {}", path.display());
21 }
22
23 // Hopefully you don't have ABS_X bound to anything important.
24 let code = AbsoluteAxisCode::ABS_X.0;
25
26 println!("Waiting for Ctrl-C...");
27 loop {
28 let down_event = *AbsoluteAxisEvent::new(AbsoluteAxisCode(code), 0);
29 device.emit(&[down_event]).unwrap();
30 println!("Minned out.");
31 sleep(Duration::from_secs(2));
32
33 let up_event = *AbsoluteAxisEvent::new(AbsoluteAxisCode(code), 512);
34 device.emit(&[up_event]).unwrap();
35 println!("Maxed out.");
36 sleep(Duration::from_secs(2));
37 }
38}

Callers

nothing calls this directly

Calls 6

AbsoluteAxisCodeClass · 0.85
buildMethod · 0.80
with_absolute_axisMethod · 0.80
emitMethod · 0.80
nameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…