objective c - Programmatically Disable Mouse & keyboard -


i programmatically disable mouse & keyboard input temporarily on mac (using objective c/c/unix) & reenable them.

i have made small open source application allows selectively disable keyboards cgeventtap function os x. inside carbon framework, based on corefoundation, works on lion. example can try open sourceapp multilayout, available here on github.

basically need if want is:

to use it, need add carbon framework:

#import <carbon/carbon.h> 

then create event tap this:

void tap_keyboard(void) {     cfrunloopsourceref runloopsource;      cgeventmask mask = kcgeventmaskforallevents;     //cgeventmask mask = cgeventmaskbit(kcgeventkeyup) | cgeventmaskbit(kcgeventkeydown);      cfmachportref eventtap = cgeventtapcreate(kcghideventtap, kcgheadinserteventtap, kcgeventtapoptiondefault, mask, mycgeventcallback, null);      if (!eventtap) {          nslog(@"couldn't create event tap!");         exit(1);     }      runloopsource = cfmachportcreaterunloopsource(kcfallocatordefault, eventtap, 0);      cfrunloopaddsource(cfrunloopgetcurrent(), runloopsource, kcfrunloopcommonmodes);      cgeventtapenable(eventtap, true);      cfrelease(eventtap);     cfrelease(runloopsource);  } 

to interrupt events when necessary, use snippet:

bool dontforwardtap = false;  cgeventref mycgeventcallback(cgeventtapproxy proxy, cgeventtype type, cgeventref event, void *refcon) {       //nslog(@"event tap: %d", (int) cgeventgetintegervaluefield(event, kcgkeyboardeventkeycode));      if (dontforwardtap)         return nil;     else         return event; } 

just set boolean dontforwardtap true, , events stopped.


Comments

Popular posts from this blog

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -

javascript - Iterate over array and calculate average values of array-parts -

jQuery Ajax Render Fragments OR Whole Page -