From 49f7a73765c34a038bfc822643177462a5cd5657 Mon Sep 17 00:00:00 2001 From: Benno Date: Wed, 1 Mar 2017 12:39:17 +0100 Subject: [PATCH] Fix CGEventTap event mask. Turns out I was using a completely wrong mask. --- NativeDisplayBrightness/AppDelegate.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/NativeDisplayBrightness/AppDelegate.m b/NativeDisplayBrightness/AppDelegate.m index 98dd9bd..34d7721 100644 --- a/NativeDisplayBrightness/AppDelegate.m +++ b/NativeDisplayBrightness/AppDelegate.m @@ -41,7 +41,7 @@ CGEventRef keyboardCGEventCallback(CGEventTapProxy proxy, CGEventRef event, void *refcon) { - //Surpress the brightness key events to prevent other applications from catching it + //Surpress the F1/F2 key events to prevent other applications from catching it or playing beep sound if (type == NX_KEYDOWN || type == NX_KEYUP || type == NX_FLAGSCHANGED) { int64_t keyCode = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode); @@ -123,8 +123,7 @@ - (void)_registerGlobalKeyboardEvents }]; CFRunLoopRef runloop = (CFRunLoopRef)CFRunLoopGetCurrent(); - - CGEventMask interestedEvents = kCGEventKeyDown | NSKeyUp; + CGEventMask interestedEvents = NX_KEYDOWNMASK | NX_KEYUPMASK | NX_FLAGSCHANGEDMASK; CFMachPortRef eventTap = CGEventTapCreate(kCGAnnotatedSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, interestedEvents, keyboardCGEventCallback, (__bridge void * _Nullable)(self)); // by passing self as last argument, you can later send events to this class instance