osx - How to discard command+shift+Q command in mac OS X objective c code? -
i'm trying implement screensaver simulator on mac os x , managed disable effect of pressing command+q causing application exit, if it's in full screen mode, not respond quit keyboard shortcut.
but, problem in handling shortcut of ( command+ shift+q) pops confirmation dialog of max os x warns exiting apps , logging of system.
can me in preventing effect of command+shift+q shortcut while being in full screen mode ?
thanks
this best answer question
first in applicationdidfinishedload function, add peace of code create event tap , add event tap in current run loop
cfmachportref eventtap; cgeventmask eventmask; cfrunloopsourceref runloopsource; // create event tap. interested in key presses. eventmask = ((1 << kcgeventkeydown) | (1 << kcgeventkeyup)); eventtap = cgeventtapcreate(kcgsessioneventtap, kcgheadinserteventtap, 0, eventmask, mycgeventcallback, null); if (!eventtap) { fprintf(stderr, "failed create event tap\n"); exit(1); } // create run loop source. runloopsource = cfmachportcreaterunloopsource( kcfallocatordefault, eventtap, 0); // add current run loop. cfrunloopaddsource(cfrunloopgetcurrent(), runloopsource, kcfrunloopcommonmodes); // enable event tap. cgeventtapenable(eventtap, true);
then in class, can implement call function called mycgeventcallback this
cgeventref mycgeventcallback(cgeventtapproxy proxy, cgeventtype type, cgeventref event, void *refcon) { // paranoid sanity check. // type key down or key up, can discard command + q setting kecode -1 if (((type == kcgeventkeydown) || (type == kcgeventkeyup))) { cgeventsetintegervaluefield( event, kcgkeyboardeventkeycode, (int64_t)-1); return event; } // incoming keycode. cgkeycode keycode = (cgkeycode)cgeventgetintegervaluefield( event, kcgkeyboardeventkeycode); // swap 'a' (keycode=0) , 'z' (keycode=6). if (keycode == (cgkeycode)0) keycode = (cgkeycode)6; else if (keycode == (cgkeycode)6) keycode = (cgkeycode)0; // set modified keycode field in event. cgeventsetintegervaluefield( event, kcgkeyboardeventkeycode, (int64_t)keycode); // must return event useful. return event; }
for original code check here
thanks
Comments
Post a Comment