evdev-rs/examples/evtest.rs
Noah 2e2d6f1468
Use typed ioctl calls + other misc changes (#29)
* Use typed ioctl calls

* Make enumerate() return an iterator instead of a vec

* Fix(?) events() behavior

* read() into a buf of mem::MaybeUninit

* Add Device.wait_ready()

* impl AsRawFd for Device

* Add remaining ioctls
2021-02-23 13:31:36 -07:00

28 lines
863 B
Rust

// Similar to the evtest tool.
use std::io::prelude::*;
fn main() {
let mut args = std::env::args_os();
let mut d = if args.len() > 1 {
evdev::Device::open(&args.nth(1).unwrap()).unwrap()
} else {
let mut devices = evdev::enumerate().collect::<Vec<_>>();
for (i, d) in devices.iter().enumerate() {
println!("{}: {:?}", i, d.name());
}
print!("Select the device [0-{}]: ", devices.len());
let _ = std::io::stdout().flush();
let mut chosen = String::new();
std::io::stdin().read_line(&mut chosen).unwrap();
devices.swap_remove(chosen.trim().parse::<usize>().unwrap())
};
println!("{}", d);
println!("Events:");
loop {
for ev in d.events_no_sync().unwrap() {
println!("{:?}", ev);
}
d.wait_ready().unwrap();
}
}