2011-06-21 5 views

Répondre

2

Trouvé Solution:

self.machPortRef = CGEventTapCreate(kCGSessionEventTap, 
              kCGTailAppendEventTap, 
              kCGEventTapOptionDefault, 
              CGEventMaskBit(kCGEventKeyDown), 
              (CGEventTapCallBack)eventTapFunction, 
              self); 
     if (self.machPortRef == NULL) 
     { 
      printf("CGEventTapCreate failed!\n"); 
     } else { 
      self.eventSrc = CFMachPortCreateRunLoopSource(NULL, self.machPortRef, 0); 
      if (self.eventSrc == NULL) 
      { 
       printf("No event run loop src?\n"); 
      }else { 
       CFRunLoopRef runLoop = CFRunLoopGetCurrent(); //GetCFRunLoopFromEventLoop(GetMainEventLoop()); 

       // Get the CFRunLoop primitive for the Carbon Main Event Loop, and add the new event souce 
       CFRunLoopAddSource(runLoop, self.eventSrc, kCFRunLoopDefaultMode); 

      } 
     } 

Propriétés:

CFMachPortRef machPortRef; 
CFRunLoopSourceRef eventSrc; 

Gestionnaire de l'événement:

CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) 
{ 
    //printf("eventTap triggered\n"); 
    return event; 
} 
Questions connexes