Actual initial commit
This commit is contained in:
43
src/main.rs
Normal file
43
src/main.rs
Normal file
@ -0,0 +1,43 @@
|
||||
use rdev::{simulate, Event, EventType, SimulateError};
|
||||
use std::process::exit;
|
||||
|
||||
const SPACE_KEY: rdev::Key = rdev::Key::Space;
|
||||
const ESCAPE_KEY: rdev::Key = rdev::Key::Escape;
|
||||
|
||||
fn send(event_type: EventType) {
|
||||
match simulate(&event_type) {
|
||||
Ok(()) => (),
|
||||
Err(SimulateError) => {
|
||||
println!("Error sending event: {:?}", event_type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let callback = |event: Event| {
|
||||
let mut matched: bool = false;
|
||||
match event.event_type {
|
||||
EventType::KeyPress(SPACE_KEY) => {
|
||||
send(EventType::ButtonPress(rdev::Button::Left));
|
||||
matched = true;
|
||||
},
|
||||
EventType::KeyRelease(SPACE_KEY) => {
|
||||
send(EventType::ButtonRelease(rdev::Button::Left));
|
||||
matched = true;
|
||||
},
|
||||
EventType::KeyPress(ESCAPE_KEY) => exit(0),
|
||||
_ => ()
|
||||
}
|
||||
if !matched {
|
||||
Some(event)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
|
||||
println!("Escape: Quit program\nSpace: Left mouse click");
|
||||
|
||||
if let Err(error) = rdev::grab(callback) {
|
||||
eprintln!("Error: {:?}", error);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user