cb2f5ef87a
* Default impl should block. Renaming it to avoid API confusion from previous users. * Can't get rid of libc::read because we have MaybeUninit, but we can clean up the match * Remove extra include * Switch everything over to io::Error * Add initial tokio impl+example * Move evtest_tokio to normal example * Add documentation and clarify * Use a VecDeque (ring buffer) instead of repeatedly popping things off the front of a Vec * Looks like we are not using thiserror anymore; removing * Store read buf between calls * Add nonblocking example with epoll Co-authored-by: Jeff Hiner <jeff-hiner@users.noreply.github.com> Co-authored-by: Noah <33094578+coolreader18@users.noreply.github.com>
27 lines
862 B
Rust
27 lines
862 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().unwrap_or("Unnamed device"));
|
|
}
|
|
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.fetch_events_no_sync().unwrap() {
|
|
println!("{:?}", ev);
|
|
}
|
|
}
|
|
}
|