From e20070860b7e8c42cebef6a76da1ccc7d16bb6ca Mon Sep 17 00:00:00 2001 From: pentamassiv Date: Wed, 8 Mar 2023 01:23:42 +0100 Subject: [PATCH] macOS: Get rid of unicode-segmentation dependency and enter 20 chars at a time --- Cargo.toml | 1 - src/macos/macos_impl.rs | 15 ++++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d9ea6e48..db234e7a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,6 @@ core-foundation-sys = "0.8" core-foundation = "0.9" core-graphics = { version = "0.22", features = ["highsierra"] } objc = "0.2" -unicode-segmentation = "1.6" [target.'cfg(target_os = "linux")'.dependencies] libc = "0.2" diff --git a/src/macos/macos_impl.rs b/src/macos/macos_impl.rs index a502582a..ef14fd7c 100644 --- a/src/macos/macos_impl.rs +++ b/src/macos/macos_impl.rs @@ -242,17 +242,18 @@ impl MouseControllable for Enigo { impl KeyboardControllable for Enigo { fn key_sequence(&mut self, sequence: &str) { // NOTE(dustin): This is a fix for issue https://github.com/enigo-rs/enigo/issues/68 - // TODO(dustin): This could be improved by aggregating 20 bytes worth of - // graphemes at a time but i am unsure what would happen for grapheme - // clusters greater than 20 bytes ... - use unicode_segmentation::UnicodeSegmentation; - let clusters = UnicodeSegmentation::graphemes(sequence, true).collect::>(); - for cluster in clusters { + // The CGEventKeyboardSetUnicodeString function (used inside of + // event.set_string(cluster)) truncates strings down to 20 characters + let chars: Vec = sequence.chars().collect(); + let mut string: String; + for chunk in chars.chunks(20) { let event = CGEvent::new_keyboard_event(self.event_source.clone(), 0, true) .expect("Failed creating event"); - event.set_string(cluster); + string = chunk.iter().collect(); + event.set_string(&string); event.post(CGEventTapLocation::HID); } + thread::sleep(Duration::from_millis(2)); } fn key_click(&mut self, key: Key) {