Add option to delay backspace presses on Linux. See #248

This commit is contained in:
Federico Terzi 2020-05-05 20:52:53 +02:00
parent 171c18873e
commit eae013d16f
4 changed files with 13 additions and 8 deletions

View File

@ -340,7 +340,7 @@ void fast_send_string(const char * string) {
fast_enter_text_window(xdo_context, focused, string, 1);
}
void _fast_send_keycode_to_focused_window(int KeyCode, int32_t count) {
void _fast_send_keycode_to_focused_window(int KeyCode, int32_t count, int32_t delay) {
int keycode = XKeysymToKeycode(xdo_context->xdpy, KeyCode);
Window focused;
@ -350,13 +350,18 @@ void _fast_send_keycode_to_focused_window(int KeyCode, int32_t count) {
for (int i = 0; i<count; i++) {
fast_send_event(xdo_context, focused, keycode, 1);
fast_send_event(xdo_context, focused, keycode, 0);
if (delay > 0) {
usleep(delay * 1000);
XFlush(xdo_context->xdpy);
}
}
XFlush(xdo_context->xdpy);
}
void fast_send_enter() {
_fast_send_keycode_to_focused_window(XK_Return, 1);
_fast_send_keycode_to_focused_window(XK_Return, 1, 0);
}
void delete_string(int32_t count) {
@ -365,8 +370,8 @@ void delete_string(int32_t count) {
}
}
void fast_delete_string(int32_t count) {
_fast_send_keycode_to_focused_window(XK_BackSpace, count);
void fast_delete_string(int32_t count, int32_t delay) {
_fast_send_keycode_to_focused_window(XK_BackSpace, count, delay);
}
void left_arrow(int32_t count) {
@ -376,7 +381,7 @@ void left_arrow(int32_t count) {
}
void fast_left_arrow(int32_t count) {
_fast_send_keycode_to_focused_window(XK_Left, count);
_fast_send_keycode_to_focused_window(XK_Left, count, 0);
}
void trigger_paste() {

View File

@ -75,7 +75,7 @@ extern "C" void delete_string(int32_t count);
/*
* Send the backspace keypress, *count* times using a faster inject method
*/
extern "C" void fast_delete_string(int32_t count);
extern "C" void fast_delete_string(int32_t count, int32_t delay);
/*
* Send an Enter key press

View File

@ -49,7 +49,7 @@ extern {
pub fn trigger_copy();
pub fn fast_send_string(string: *const c_char);
pub fn fast_delete_string(count: i32);
pub fn fast_delete_string(count: i32, delay: i32);
pub fn fast_left_arrow(count: i32);
pub fn fast_send_enter();
}

View File

@ -93,7 +93,7 @@ impl super::KeyboardManager for LinuxKeyboardManager {
fn delete_string(&self, active_config: &Configs, count: i32) {
unsafe {
if active_config.fast_inject {
fast_delete_string(count);
fast_delete_string(count, active_config.backspace_delay);
}else{
delete_string(count)
}