6c1add8b73
* Prototype support for virtual uinput devices * Tidy uinput a bit * Have all the evtest examples use the same args/prompt code * Switch to libc uinput* structs * Use InputId in uinput, use libc _CNT constants * Don't use align_to_mut * Only check /dev/input/eventN files * Spelling fixup * Fix compilation error * Ah, there we go. Much better. Co-authored-by: Jeff Hiner <jeff-hiner@users.noreply.github.com> Co-authored-by: Noah <33094578+coolreader18@users.noreply.github.com>
28 lines
1,008 B
Rust
28 lines
1,008 B
Rust
//! An arg parser/prompt shared between the `evtest*` examples. Also demonstrates opening/finding
|
|
//! connected devices.
|
|
|
|
use std::io::prelude::*;
|
|
|
|
pub fn pick_device() -> evdev::Device {
|
|
let mut args = std::env::args_os();
|
|
args.next();
|
|
if let Some(dev_file) = args.next() {
|
|
evdev::Device::open(dev_file).unwrap()
|
|
} else {
|
|
let mut devices = evdev::enumerate().collect::<Vec<_>>();
|
|
// readdir returns them in reverse order from their eventN names for some reason
|
|
devices.reverse();
|
|
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();
|
|
let n = chosen.trim().parse::<usize>().unwrap();
|
|
devices.into_iter().nth(n).unwrap()
|
|
}
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
fn main() {}
|