From e6bbf08a9dfa555059b6dfb30470f09a409565b9 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Wed, 10 Jun 2020 20:32:46 +0200 Subject: [PATCH] Release SHIFT key if pressed when expanding on macOS. Fix #279 --- native/libmacbridge/bridge.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/native/libmacbridge/bridge.mm b/native/libmacbridge/bridge.mm index 3e2d7e5..1ddd549 100644 --- a/native/libmacbridge/bridge.mm +++ b/native/libmacbridge/bridge.mm @@ -87,6 +87,16 @@ void send_string(const char * string) { // Send the event + // Check if the shift key is down, and if so, release it + // To see why: https://github.com/federico-terzi/espanso/issues/279 + if (CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, 0x38)) { + CGEventRef e2 = CGEventCreateKeyboardEvent(NULL, 0x38, false); + CGEventPost(kCGHIDEventTap, e2); + CFRelease(e2); + + usleep(2000); + } + // Because of a bug ( or undocumented limit ) of the CGEventKeyboardSetUnicodeString method // the string gets truncated after 20 characters, so we need to send multiple events.