2015-07-07 22:31:28 +00:00
|
|
|
// Similar to the evtest tool.
|
|
|
|
|
|
|
|
use std::io::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut args = std::env::args_os();
|
2021-02-23 20:31:36 +00:00
|
|
|
let mut d = if args.len() > 1 {
|
|
|
|
evdev::Device::open(&args.nth(1).unwrap()).unwrap()
|
2015-07-07 22:31:28 +00:00
|
|
|
} else {
|
2021-02-23 20:31:36 +00:00
|
|
|
let mut devices = evdev::enumerate().collect::<Vec<_>>();
|
2015-07-07 22:31:28 +00:00
|
|
|
for (i, d) in devices.iter().enumerate() {
|
2021-02-24 16:54:55 +00:00
|
|
|
println!("{}: {}", i, d.name().unwrap_or("Unnamed device"));
|
2015-07-07 22:31:28 +00:00
|
|
|
}
|
|
|
|
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();
|
2021-02-23 20:31:36 +00:00
|
|
|
devices.swap_remove(chosen.trim().parse::<usize>().unwrap())
|
|
|
|
};
|
2015-07-07 22:31:28 +00:00
|
|
|
println!("{}", d);
|
|
|
|
println!("Events:");
|
|
|
|
loop {
|
2021-03-01 17:09:11 +00:00
|
|
|
for ev in d.fetch_events_no_sync().unwrap() {
|
2015-07-07 22:31:28 +00:00
|
|
|
println!("{:?}", ev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|