From 9521e26cbc9cc7602dc3f5390f1e8d076d743d21 Mon Sep 17 00:00:00 2001 From: Gabriel <68819302+obsidianical@users.noreply.github.com> Date: Mon, 11 Jul 2022 12:18:43 +0200 Subject: [PATCH] "started" working on event_delay support. and added to the TODOs. --- README.md | 3 +++ src/bin/easymacroplay.rs | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 93f3272..333f020 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,9 @@ This program is inspired by [**xmacro**](https://github.com/Ortega-Dan/xmacroInc - [x] Delay - [x] Keyboard actions - [x] Mouse actions +- [ ] Utilities for playing macros + - [ ] Ignoring delays when playing + - [ ] Event delay support # diff --git a/src/bin/easymacroplay.rs b/src/bin/easymacroplay.rs index 430c94a..ba358d5 100644 --- a/src/bin/easymacroplay.rs +++ b/src/bin/easymacroplay.rs @@ -8,7 +8,7 @@ use std::io::stdin; use x11::keysym::XK_Shift_L; use easymacros::chartbl::CHARTBL; -/// Macro player module for easymacros. It's partially compatible with xmacro macros, with aim for full compatibility. +/// Macro player module for easymacros. It's compatible with xmacro macros. #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] struct Args { @@ -16,8 +16,11 @@ struct Args { #[clap(value_parser, value_name = "input_file", value_hint = clap::ValueHint::FilePath)] input_file: Option, /// Display to run the macro on. This uses the $DISPLAY environment variable by default. - #[clap(short, long)] + #[clap(short = "D", long)] display: Option, + // Delay for events to be sent. + // #[clap(short, long)] + // event_delay: Option, } fn main() { @@ -33,6 +36,7 @@ fn main() { run_instruction(instruction, &display); } } else { + println!("No input file specified, reading from stdin."); let stdin = stdin(); loop { @@ -45,8 +49,6 @@ fn main() { } } - - display.close(); } @@ -106,18 +108,17 @@ fn run_instruction(instruction: &str, dpy: &XDisplay) { command.arg(arg); } if instruction_split[0] == "ExecBlock" { - command.status(); + command.status().unwrap(); } else { - command.spawn(); + command.spawn().unwrap(); } } - c => { - panic!("Unknown command {:?}", instruction_split) - } + c => panic!("Unknown command {:?}", instruction_split), } } fn send_char(dpy: &XDisplay, c: char) { + // get keystring from character and turn it into a keysym let keysym = string_to_keysym(CHARTBL[c as usize].as_ref()); let keycode = dpy.keysym_to_keycode(keysym); @@ -127,13 +128,14 @@ fn send_char(dpy: &XDisplay, c: char) { } let map_ks = dpy.get_keyboard_mapping(keycode, 1); - if unsafe { map_ks[0] } == 0 { + if map_ks[0] == 0 { eprintln!("XGetKeyboardMapping failed (keycode: {})", keycode); return; } let (ks_lower, ks_upper) = dpy.convert_case(keysym); + // check if shift has to be pressed as well let mut shift_needed = true; if keysym == map_ks[0] && (keysym == ks_lower && keysym == ks_upper) { shift_needed = false;