From 97130e972c294095b3331045de7604dab1c3978d Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Sat, 14 Aug 2021 16:07:14 +0200 Subject: [PATCH] feat(detect): filter out espanso-generated events on macOS --- espanso-detect/src/mac/native.mm | 8 ++++++++ 1 file changed, 8 insertions(+) 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;