apparently changed names and optimized inputs

This commit is contained in:
Schrottkatze 2022-07-03 15:23:21 +02:00
parent cedebb4b6d
commit c695d803e0
2 changed files with 16 additions and 17 deletions

View file

@ -63,35 +63,35 @@ fn get_remote(display_name: Option<String>) -> XDisplay {
display display
} }
fn run_instruction(instruction: &str, display: &XDisplay) { fn run_instruction(instruction: &str, dpy: &XDisplay) {
let instruction: Vec<&str> = instruction.split(' ').collect(); let instruction: Vec<&str> = instruction.split(' ').collect();
match instruction[0] { match instruction[0] {
"Delay" => thread::sleep(Duration::from_millis(instruction[1].parse().unwrap())), "Delay" => thread::sleep(Duration::from_millis(instruction[1].parse().unwrap())),
"ButtonPress" => display.send_fake_buttonpress(instruction[1].parse().unwrap()), "ButtonPress" => dpy.send_fake_buttonpress(instruction[1].parse().unwrap()),
"ButtonRelease" => display.send_fake_buttonrelease(instruction[1].parse().unwrap()), "ButtonRelease" => dpy.send_fake_buttonrelease(instruction[1].parse().unwrap()),
"MotionNotify" => display "MotionNotify" => dpy
.send_fake_motion_event(instruction[1].parse().unwrap(), instruction[2].parse().unwrap()), .send_fake_motion_event(instruction[1].parse().unwrap(), instruction[2].parse().unwrap()),
"KeyCodePress" => display.send_fake_keypress_from_code(instruction[1].parse().unwrap()), "KeyCodePress" => dpy.send_fake_keypress_from_code(instruction[1].parse().unwrap()),
"KeyCodeRelease" => display.send_fake_keyrelease_from_code(instruction[1].parse().unwrap()), "KeyCodeRelease" => dpy.send_fake_keyrelease_from_code(instruction[1].parse().unwrap()),
"KeySymPress" => display.send_fake_keypress_from_keysym(instruction[1].parse().unwrap()), "KeySymPress" => dpy.send_fake_keypress_from_keysym(instruction[1].parse().unwrap()),
"KeySymRelease" => { "KeySymRelease" => {
display.send_fake_keyrelease_from_keysym(instruction[1].parse().unwrap()) dpy.send_fake_keyrelease_from_keysym(instruction[1].parse().unwrap())
} }
"KeySym" => { "KeySym" => {
let key: Keysym = instruction[1].parse().unwrap(); let key: Keysym = instruction[1].parse().unwrap();
display.send_fake_keypress_from_keysym(key); dpy.send_fake_keypress_from_keysym(key);
display.send_fake_keyrelease_from_keysym(key); dpy.send_fake_keyrelease_from_keysym(key);
} }
"KeyStrPress" => { "KeyStrPress" => {
display.send_fake_keypress_from_string(CString::new(instruction[1]).unwrap().as_bytes()) dpy.send_fake_keypress_from_string(CString::new(instruction[1]).unwrap().as_bytes())
} }
"KeyStrRelease" => display "KeyStrRelease" => dpy
.send_fake_keyrelease_from_string(CString::new(instruction[1]).unwrap().as_bytes()), .send_fake_keyrelease_from_string(CString::new(instruction[1]).unwrap().as_bytes()),
"KeyStr" => { "KeyStr" => {
let keystring = CString::new(instruction[1]).unwrap(); let keystring = CString::new(instruction[1]).unwrap();
display.send_fake_keypress_from_string(keystring.as_bytes()); dpy.send_fake_keypress_from_string(keystring.as_bytes());
display.send_fake_keyrelease_from_string(keystring.as_bytes()); dpy.send_fake_keyrelease_from_string(keystring.as_bytes());
} }
"String" => { "String" => {
println!("Strings are currently not supported."); println!("Strings are currently not supported.");

View file

@ -1,9 +1,8 @@
use std::cell::{Ref, RefCell};
use std::env; use std::env;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::os::raw::{c_char, c_int, c_uchar, c_uint, c_ulong}; use std::os::raw::{c_char, c_int, c_uchar, c_uint, c_ulong};
use x11::xlib::{Display, GenericEvent, KeyCode, KeyPress, MotionNotify, Status, Time, Window, XAllowEvents, XAnyEvent, XCloseDisplay, XDefaultScreen, XEvent, XFlush, XGrabKeyboard, XID, XKeycodeToKeysym, XKeyEvent, XKeysymToKeycode, XKeysymToString, XOpenDisplay, XQueryPointer, XRootWindow, XStringToKeysym, XSync, XUngrabKeyboard, XUngrabPointer, XWindowEvent}; use x11::xlib::{Display, GenericEvent, KeyPress, MotionNotify, Time, Window, XAllowEvents, XCloseDisplay, XDefaultScreen, XEvent, XFlush, XGrabKeyboard, XKeycodeToKeysym, XKeysymToKeycode, XKeysymToString, XOpenDisplay, XQueryPointer, XRootWindow, XStringToKeysym, XSync, XUngrabKeyboard, XUngrabPointer, XWindowEvent};
use x11::xrecord::{XRecordAllClients, XRecordAllocRange, XRecordClientInfo, XRecordClientSpec, XRecordContext, XRecordCreateContext, XRecordDisableContext, XRecordEnableContext, XRecordEnableContextAsync, XRecordFreeContext, XRecordInterceptData, XRecordProcessReplies, XRecordQueryVersion, XRecordRange}; use x11::xrecord::{XRecordAllClients, XRecordClientSpec, XRecordContext, XRecordCreateContext, XRecordDisableContext, XRecordEnableContext, XRecordEnableContextAsync, XRecordFreeContext, XRecordInterceptData, XRecordProcessReplies, XRecordQueryVersion, XRecordRange};
use x11::xtest::{ use x11::xtest::{
XTestFakeButtonEvent, XTestFakeKeyEvent, XTestFakeMotionEvent, XTestGrabControl, XTestFakeButtonEvent, XTestFakeKeyEvent, XTestFakeMotionEvent, XTestGrabControl,
XTestQueryExtension, XTestQueryExtension,