evdev-rs/examples/evtest_tokio.rs
Noah 3581aa25e0
Syncing impl (#36)
* WIP syncing impl

* Finish up syncing impl

* Reorganize synchronization code + add more docs

* Wrap libc::input_id

* Remove thread::sleep used for testing

* Make EventStream::Item io::Result<InputEvent>

* Add RawDevice::empty_state()

* Update Device rustdoc

* Make raw/sync_stream naming consistent

* Update crate docs

* Fix missing first event of block

* Owned AttributeSet, borrowed AttributeSetRef

* Add some basic syncing tests

* Add some more syncing tests
2021-03-16 20:38:42 -06:00

27 lines
904 B
Rust

use tokio_1 as tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut args = std::env::args_os();
let d = if args.len() > 1 {
evdev::Device::open(&args.nth(1).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::Write::flush(&mut std::io::stdout());
let mut chosen = String::new();
std::io::stdin().read_line(&mut chosen)?;
devices.swap_remove(chosen.trim().parse::<usize>()?)
};
println!("{}", d);
println!("Events:");
let mut events = d.into_event_stream()?;
loop {
let ev = events.next_event().await?;
println!("{:?}", ev);
}
}