Compare commits
2 Commits
748665ef5e
...
3eb031134b
Author | SHA1 | Date | |
---|---|---|---|
3eb031134b | |||
7873309212 |
@ -2,7 +2,7 @@ name: Rust
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: ["master"]
|
branches: ["main"]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
30
src/main.rs
30
src/main.rs
@ -1,8 +1,10 @@
|
|||||||
|
use std::sync::{Arc, Mutex};
|
||||||
use rdev::{simulate, Event, EventType, SimulateError};
|
use rdev::{simulate, Event, EventType, SimulateError};
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
|
||||||
const SPACE_KEY: rdev::Key = rdev::Key::Space;
|
const SPACE_KEY: rdev::Key = rdev::Key::Space;
|
||||||
const ESCAPE_KEY: rdev::Key = rdev::Key::Escape;
|
const ESCAPE_KEY: rdev::Key = rdev::Key::Escape;
|
||||||
|
const SUSPEND_KEY: rdev::Key = rdev::Key::SemiColon;
|
||||||
|
|
||||||
fn send(event_type: EventType) {
|
fn send(event_type: EventType) {
|
||||||
match simulate(&event_type) {
|
match simulate(&event_type) {
|
||||||
@ -14,18 +16,36 @@ fn send(event_type: EventType) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let callback = |event: Event| {
|
let suspended = Arc::new(Mutex::new(false));
|
||||||
|
let suspended_clone = Arc::clone(&suspended);
|
||||||
|
|
||||||
|
let callback = move |event: Event| {
|
||||||
let mut matched: bool = false;
|
let mut matched: bool = false;
|
||||||
match event.event_type {
|
match event.event_type {
|
||||||
EventType::KeyPress(SPACE_KEY) => {
|
EventType::KeyPress(key) if key == SPACE_KEY => {
|
||||||
|
let suspended = suspended.lock().unwrap();
|
||||||
|
if *suspended {
|
||||||
|
return Some(event);
|
||||||
|
} else {
|
||||||
send(EventType::ButtonPress(rdev::Button::Left));
|
send(EventType::ButtonPress(rdev::Button::Left));
|
||||||
matched = true;
|
matched = true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
EventType::KeyRelease(SPACE_KEY) => {
|
EventType::KeyRelease(key) if key == SPACE_KEY => {
|
||||||
|
let suspended = suspended.lock().unwrap();
|
||||||
|
if *suspended {
|
||||||
|
return Some(event);
|
||||||
|
} else {
|
||||||
send(EventType::ButtonRelease(rdev::Button::Left));
|
send(EventType::ButtonRelease(rdev::Button::Left));
|
||||||
matched = true;
|
matched = true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
EventType::KeyPress(ESCAPE_KEY) => exit(0),
|
EventType::KeyPress(key) if key == SUSPEND_KEY => {
|
||||||
|
let mut suspended = suspended_clone.lock().unwrap();
|
||||||
|
*suspended = !*suspended;
|
||||||
|
println!("Suspend: {}", *suspended);
|
||||||
|
}
|
||||||
|
EventType::KeyPress(key) if key == ESCAPE_KEY => exit(0),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
if !matched {
|
if !matched {
|
||||||
@ -35,7 +55,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Escape: Quit program\nSpace: Left mouse click");
|
println!("Escape: Quit program\nSemi colon (;): Suspend\nSpace: Left mouse click");
|
||||||
|
|
||||||
if let Err(error) = rdev::grab(callback) {
|
if let Err(error) = rdev::grab(callback) {
|
||||||
eprintln!("Error: {:?}", error);
|
eprintln!("Error: {:?}", error);
|
||||||
|
Loading…
Reference in New Issue
Block a user