From 9551329392ee597b2781626d38b4f249c71b96c1 Mon Sep 17 00:00:00 2001 From: "Jerry (Xinyu Hou)" Date: Wed, 10 May 2017 16:24:44 +0100 Subject: [PATCH] Compare source pid from event to detect local input on Mac --- src/lib/platform/OSXScreen.mm | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index d96ed1ab..4915231d 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -1844,20 +1844,18 @@ OSXScreen::handleCGInputEventSecondary( CGEventRef event, void* refcon) { - CGEventMask mask = kCGEventFlagMaskCommand; - mask = CGEventGetFlags(event); - LOG ((CLOG_INFO "%x", mask)); - auto i = CGEventGetIntegerValueField(event, kCGEventSourceUnixProcessID); - LOG ((CLOG_INFO "Target PID:%lld", i)); + static pid_t currentPid = getpid(); + auto sourcePid = CGEventGetIntegerValueField(event, kCGEventSourceUnixProcessID); - switch(type) { - case kCGEventLeftMouseDown: - case kCGEventRightMouseDown: - case kCGEventOtherMouseDown: - case kCGEventScrollWheel: - case kCGEventKeyDown: - case kCGEventFlagsChanged: - ;//LOG((CLOG_INFO "local input detected")); + if (currentPid != sourcePid) { + switch(type) { + case kCGEventLeftMouseDown: + case kCGEventRightMouseDown: + case kCGEventOtherMouseDown: + case kCGEventKeyDown: + case kCGEventFlagsChanged: + LOG((CLOG_INFO "local input detected")); + } } return event;