From 13a9921a5c5c9b32a58a9f9f20bc841c6db948c2 Mon Sep 17 00:00:00 2001 From: Johannes Leupolz Date: Sat, 13 Dec 2025 23:09:31 +0000 Subject: [PATCH] Fixes in examples --- vuinput-examples/src/bin/keyboard-advanced.rs | 10 ++++++++-- vuinput-examples/src/bin/mouse-advanced.rs | 2 +- vuinput-examples/src/bin/mouse-reuse.rs | 2 +- vuinputd-tests/src/bin/keyboard-in-container.rs | 14 ++++++++++---- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/vuinput-examples/src/bin/keyboard-advanced.rs b/vuinput-examples/src/bin/keyboard-advanced.rs index 61a4e13..1ee2c24 100644 --- a/vuinput-examples/src/bin/keyboard-advanced.rs +++ b/vuinput-examples/src/bin/keyboard-advanced.rs @@ -305,8 +305,14 @@ fn emit(fd: c_int, ev_type: i32, code: i32, val: i32) -> io::Result<()> { } fn main() -> io::Result<()> { - // open device - matches: open("/dev/uinput-test", O_WRONLY | O_NONBLOCK); - let path = CString::new("/dev/uinput-test").unwrap(); + // open device - matches: open("/dev/uinput", O_WRONLY | O_NONBLOCK); + let args: Vec = std::env::args().collect(); + let device = match args.len() { + 2 => args[1].clone(), + _ => "/dev/uinput".to_string(), + }; + + let path = CString::new(device).unwrap(); let fd = unsafe { open(path.as_ptr(), O_WRONLY | O_NONBLOCK) }; if fd < 0 { eprintln!("error opening uinput"); diff --git a/vuinput-examples/src/bin/mouse-advanced.rs b/vuinput-examples/src/bin/mouse-advanced.rs index e1c77e5..6b872a4 100644 --- a/vuinput-examples/src/bin/mouse-advanced.rs +++ b/vuinput-examples/src/bin/mouse-advanced.rs @@ -58,7 +58,7 @@ fn emit(fd: c_int, ev_type: i32, code: i32, val: i32) -> io::Result<()> { } fn main() -> io::Result<()> { - // open device - matches: open("/dev/uinput-test", O_WRONLY | O_NONBLOCK); + // open device - matches: open("/dev/uinput", O_WRONLY | O_NONBLOCK); let args: Vec = std::env::args().collect(); let device = match args.len() { diff --git a/vuinput-examples/src/bin/mouse-reuse.rs b/vuinput-examples/src/bin/mouse-reuse.rs index 06c34a5..855a5ee 100644 --- a/vuinput-examples/src/bin/mouse-reuse.rs +++ b/vuinput-examples/src/bin/mouse-reuse.rs @@ -58,7 +58,7 @@ fn emit(fd: c_int, ev_type: i32, code: i32, val: i32) -> io::Result<()> { } fn main() -> io::Result<()> { - // open device - matches: open("/dev/uinput-test", O_WRONLY | O_NONBLOCK); + // open device - matches: open("/dev/uinput", O_WRONLY | O_NONBLOCK); let args: Vec = std::env::args().collect(); let device = match args.len() { diff --git a/vuinputd-tests/src/bin/keyboard-in-container.rs b/vuinputd-tests/src/bin/keyboard-in-container.rs index 61a4e13..43c1908 100644 --- a/vuinputd-tests/src/bin/keyboard-in-container.rs +++ b/vuinputd-tests/src/bin/keyboard-in-container.rs @@ -305,8 +305,14 @@ fn emit(fd: c_int, ev_type: i32, code: i32, val: i32) -> io::Result<()> { } fn main() -> io::Result<()> { - // open device - matches: open("/dev/uinput-test", O_WRONLY | O_NONBLOCK); - let path = CString::new("/dev/uinput-test").unwrap(); + // open device - matches: open("/dev/uinput", O_WRONLY | O_NONBLOCK); + let args: Vec = std::env::args().collect(); + let device = match args.len() { + 2 => args[1].clone(), + _ => "/dev/uinput".to_string(), + }; + + let path = CString::new(device).unwrap(); let fd = unsafe { open(path.as_ptr(), O_WRONLY | O_NONBLOCK) }; if fd < 0 { eprintln!("error opening uinput"); @@ -374,7 +380,7 @@ fn main() -> io::Result<()> { eprintln!("sysname: {}", sysname); // Sleep 1 second to allow userspace to detect the device (same as C example) - sleep(Duration::from_secs(10)); + sleep(Duration::from_secs(1)); // Emit press + syn + release + syn emit(fd, EV_KEY, KEY_SPACE, 1)?; @@ -383,7 +389,7 @@ fn main() -> io::Result<()> { emit(fd, EV_SYN, SYN_REPORT, 0)?; // Give userspace time to read events - sleep(Duration::from_secs(10)); + sleep(Duration::from_secs(2)); // Destroy device and close fd ui_dev_destroy(fd).unwrap_or_else(|e| {