diff --git a/espanso-inject/src/mac/mod.rs b/espanso-inject/src/mac/mod.rs index 2bb12d7..fc8a2ee 100644 --- a/espanso-inject/src/mac/mod.rs +++ b/espanso-inject/src/mac/mod.rs @@ -32,7 +32,7 @@ use crate::{keys, InjectionOptions, Injector}; #[allow(improper_ctypes)] #[link(name = "espansoinject", kind = "static")] extern "C" { - pub fn inject_string(string: *const c_char); + pub fn inject_string(string: *const c_char, delay: i32); pub fn inject_separate_vkeys(vkey_array: *const i32, vkey_count: i32, delay: i32); pub fn inject_vkeys_combination(vkey_array: *const i32, vkey_count: i32, delay: i32); } @@ -60,10 +60,10 @@ impl MacInjector { } impl Injector for MacInjector { - fn send_string(&self, string: &str, _: InjectionOptions) -> Result<()> { + fn send_string(&self, string: &str, options: InjectionOptions) -> Result<()> { let c_string = CString::new(string)?; unsafe { - inject_string(c_string.as_ptr()); + inject_string(c_string.as_ptr(), options.delay); } Ok(()) } diff --git a/espanso-inject/src/mac/native.h b/espanso-inject/src/mac/native.h index 6d52913..abab728 100644 --- a/espanso-inject/src/mac/native.h +++ b/espanso-inject/src/mac/native.h @@ -23,7 +23,7 @@ #include // Inject a complete string using the KEYEVENTF_UNICODE flag -extern "C" void inject_string(char * string); +extern "C" void inject_string(char * string, int32_t delay); // Send a sequence of vkey presses and releases extern "C" void inject_separate_vkeys(int32_t *vkey_array, int32_t vkey_count, int32_t delay); diff --git a/espanso-inject/src/mac/native.mm b/espanso-inject/src/mac/native.mm index cecbb56..8828c28 100644 --- a/espanso-inject/src/mac/native.mm +++ b/espanso-inject/src/mac/native.mm @@ -27,8 +27,10 @@ // so that we can later skip them in the detect module. CGPoint ESPANSO_POINT_MARKER = CGPointMake(-27469, 0); -void inject_string(char *string) +void inject_string(char *string, int32_t delay) { + long udelay = delay * 1000; + char * stringCopy = strdup(string); dispatch_async(dispatch_get_main_queue(), ^(void) { // Convert the c string to a UniChar array as required by the CGEventKeyboardSetUnicodeString method @@ -49,7 +51,7 @@ void inject_string(char *string) CGEventPost(kCGHIDEventTap, e2); CFRelease(e2); - usleep(2000); + usleep(udelay); } // Because of a bug ( or undocumented limit ) of the CGEventKeyboardSetUnicodeString method @@ -69,7 +71,7 @@ void inject_string(char *string) CGEventPost(kCGHIDEventTap, e); CFRelease(e); - usleep(2000); + usleep(udelay); // Some applications require an explicit release of the space key // For more information: https://github.com/federico-terzi/espanso/issues/159 @@ -78,7 +80,7 @@ void inject_string(char *string) CGEventPost(kCGHIDEventTap, e2); CFRelease(e2); - usleep(2000); + usleep(udelay); i += chunk_size; }