2011-06-21 7 views

答えて

2

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); 

      } 
     } 

プロパティ:

CFMachPortRef machPortRef; 
CFRunLoopSourceRef eventSrc; 

イベントハンドラ:

CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) 
{ 
    //printf("eventTap triggered\n"); 
    return event; 
} 
関連する問題