bizi
bizi

Reputation: 3457

OSX: Monitoring Event when Mission Control is activated

I am trying to listen to Mouse Event and Keyboard Event by attaching global event listener, as describe in this great thread.

However, when Mission Control is called, it seems that it blocks my listeners. I really appreciate any suggestion on how to work around this.

Upvotes: 2

Views: 400

Answers (1)

jburns20
jburns20

Reputation: 3167

I was able to get around this problem by using event taps, which are available in the Carbon Quartz Event Services Library.

Objective-C sample code (I couldn't get it working in Swift):

Assuming you have defined a C function

CGEventRef yourCallbackFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *userinfo);

you can then use this code to listen for the event SomeEventHere:

CFMachPortRef ref = CGEventTapCreate(kCGHIDEventTap, 
                                     kCGHeadInsertEventTap,
                                     kCGEventTapOptionListenOnly, 
                                     CGEventMaskBit(kCGEventSomeEventHere),
                                     (CGEventTapCallBack)yourCallbackFunction,
                                     userinfo);
CFRunLoopSourceRef src = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, ref, 0);
CFRunLoopAddSource(CFRunLoopGetMain(), src, kCFRunLoopDefaultMode);

Upvotes: -1

Related Questions