Skip to content

Commit

Permalink
macOS: Get rid of unicode-segmentation dependency and enter 20 chars …
Browse files Browse the repository at this point in the history
…at a time
  • Loading branch information
pentamassiv committed Mar 8, 2023
1 parent 8612b75 commit e200708
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 8 additions & 7 deletions src/macos/macos_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<&str>>();
for cluster in clusters {
// The CGEventKeyboardSetUnicodeString function (used inside of
// event.set_string(cluster)) truncates strings down to 20 characters
let chars: Vec<char> = 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) {
Expand Down

0 comments on commit e200708

Please sign in to comment.