cocoa - CGEventTap blocks application input -


i'm trying use cgcreateeventtap monitor global mouse clicks, when seems block interaction own app. mouse clicks in other running apps work fine, own app (that demoappdelegate app) not respond completely. can drag main window app, red/yellow/green window buttons greyed out. , demoapp's menu unclickable well.

this seems strange me, , i've been unable figure out. examples of using event taps few , far between, advice appreciated.

#import "demoappdelegate.h"  cgeventref mycgeventcallback(cgeventtapproxy proxy, cgeventtype type, cgeventref event, void *refcon) {     cgpoint location = cgeventgetlocation(event);     nslog(@"location:  (%f, %f) - %@\n", location.x, location.y, (nsstring*)refcon);     return event; }  @implementation demoappdelegate @synthesize window;  - (void)applicationdidfinishlaunching:(nsnotification *)anotification {     cfmachportref eventtap;     cgeventmask        eventmask;     cfrunloopsourceref runloopsource;     eventmask = 1 << kcgeventleftmousedown;     eventtap = cgeventtapcreate(kcgsessioneventtap, kcgheadinserteventtap,                                 1, eventmask, mycgeventcallback, @"mydata");     runloopsource = cfmachportcreaterunloopsource(kcfallocatordefault, eventtap, 0);     cfrunloopaddsource(cfrunloopgetcurrent(), runloopsource,                        kcfrunloopcommonmodes);     cgeventtapenable(eventtap, true);     cfrunlooprun(); } @end 

when create cocoa application, -[nsapplication run] responsible running event loop — runs run loop, , dispatches events. means should remove that

cfrunlooprun(); 

call @ bottom of -applicationdidfinishlaunching: method implementation, since prevents -applicationdidfinishlaunching: returning , prevents nsapplication dispatching events.


Comments

Popular posts from this blog

WPF: binding viewmodel property of type DateTime to Calendar inside ItemsControl -

java - Getting corefrences with Standard corenlp package -

Java - Returning an array from a method to main -