diff --git a/espanso-detect/src/mac/native.mm b/espanso-detect/src/mac/native.mm index 3605be9..6eb5e9a 100644 --- a/espanso-detect/src/mac/native.mm +++ b/espanso-detect/src/mac/native.mm @@ -24,6 +24,8 @@ #include +const float ESPANSO_EVENT_MARKER = -27469; + const unsigned long long FLAGS = NSEventMaskKeyDown | NSEventMaskKeyUp | NSEventMaskFlagsChanged | NSEventMaskLeftMouseDown | NSEventMaskLeftMouseUp | NSEventMaskRightMouseDown | NSEventMaskRightMouseUp | NSEventMaskOtherMouseDown | NSEventMaskOtherMouseUp; @@ -58,6 +60,12 @@ void * detect_initialize(EventCallback callback, InitializeOptions options) { // Setup key detection [NSEvent addGlobalMonitorForEventsMatchingMask:FLAGS handler:^(NSEvent *event){ + // Workaround used to determine if the event was generated by espanso itself + float eventLocation = event.locationInWindow.x; + if (fabs(eventLocation - ESPANSO_EVENT_MARKER) < 0.001) { + return; + } + InputEvent inputEvent = {}; if (event.type == NSEventTypeKeyDown || event.type == NSEventTypeKeyUp ) { inputEvent.event_type = INPUT_EVENT_TYPE_KEYBOARD;