2016-01-03 124 views
0

這裏定義爲我的事件循環:類型,應用程序包

while (!shutdown_now_) 
    { 
     NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 
     NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask 
              untilDate:[NSDate distantFuture] 
               inMode:NSDefaultRunLoopMode 
               dequeue:YES]; 
     if (event.type == NSAppKitDefined) 
     { 
      NSLog(@"NSAppKitDefinedEvent with subtype: %d", event.subtype); 
     } 
     if (event) [NSApp sendEvent:event]; 
     [pool drain]; 
    } 

類型由應用程序套件定義是:

enum { 
    NSWindowExposedEventType = 0, 
    NSApplicationActivatedEventType = 1, 
    NSApplicationDeactivatedEventType = 2, 
    NSWindowMovedEventType = 4, 
    NSScreenChangedEventType = 8, 
    NSAWTEventType = 16 
}; 

但是,我得到其他枚舉,如:9,21,22,30和更多。 這些類型定義在哪裏?

+1

請注意,這是行不通的;如果你這樣做,你並沒有運行主線程的運行循環,因此,依賴於主運行循環運行的所有類型的服務都無法工作。 – bbum

回答

1

您正在使用錯誤的枚舉(NSEventSubtype)。 event.type是NSEventType類型。

enum NSEventType : UInt { 
    case LeftMouseDown 
    case LeftMouseUp 
    case RightMouseDown 
    case RightMouseUp 
    case MouseMoved 
    case LeftMouseDragged 
    case RightMouseDragged 
    case MouseEntered 
    case MouseExited 
    case KeyDown 
    case KeyUp 
    case FlagsChanged 
    case AppKitDefined 
    case SystemDefined 
    case ApplicationDefined 
    case Periodic 
    case CursorUpdate 
    case ScrollWheel 
    case TabletPoint 
    case TabletProximity 
    case OtherMouseDown 
    case OtherMouseUp 
    case OtherMouseDragged 
    case EventTypeGesture 
    case EventTypeMagnify 
    case EventTypeSwipe 
    case EventTypeRotate 
    case EventTypeBeginGesture 
    case EventTypeEndGesture 
    case EventTypeSmartMagnify 
    case EventTypeQuickLook 
}