mirror of
https://github.com/joleuger/vuinputd.git
synced 2026-07-17 16:36:03 +00:00
Fixes in examples
This commit is contained in:
parent
1683829780
commit
13a9921a5c
4 changed files with 20 additions and 8 deletions
|
|
@ -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<String> = 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");
|
||||
|
|
|
|||
|
|
@ -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<String> = std::env::args().collect();
|
||||
let device = match args.len() {
|
||||
|
|
|
|||
|
|
@ -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<String> = std::env::args().collect();
|
||||
let device = match args.len() {
|
||||
|
|
|
|||
|
|
@ -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<String> = 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| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue