イベントキューから指定したマスク、モード、期限にあったイベントを返します
- (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)flag
func nextEventMatchingMask(_ mask: Int, untilDate expiration: NSDate?, inMode mode: String, dequeue flag: Bool) -> NSEvent?
解説
イベントキューから指定したマスク、モード、期限にあったイベントを返します。dequeueフラグをYESにすると、キューから削除されます。
【mask】
● NSLeftMouseDownMask 左マウスボタンを押した
● NSLeftMouseUpMask 左マウスボタンを離した
● NSRightMouseDownMask 右マウスボタンを押した
● NSRightMouseUpMask 右マウスボタンを離した
● NSMouseMovedMask マウスを動かした
● NSLeftMouseDraggedMask
● NSRightMouseDraggedMask
● NSMouseEnteredMask
● NSMouseExitedMask
● NSKeyDownMask
● NSKeyUpMask
● NSFlagsChangedMask
● NSPeriodicMask
● NSCursorUpdateMask
● NSAnyEventMask
【mode】モード
● NSDefaultRunLoopMode
● NSEventTrackingRunLoopMode
● NSModalPanelRunLoopMode
● NSConnectionReplyMode
Swift
【NSEventMask】
static var LeftMouseDownMask: NSEventMask { get }
static var LeftMouseUpMask: NSEventMask { get }
static var RightMouseDownMask: NSEventMask { get }
static var RightMouseUpMask: NSEventMask { get }
static var MouseMovedMask: NSEventMask { get }
static var LeftMouseDraggedMask: NSEventMask { get }
static var RightMouseDraggedMask: NSEventMask { get }
static var MouseEnteredMask: NSEventMask { get }
static var MouseExitedMask: NSEventMask { get }
static var KeyDownMask: NSEventMask { get }
static var KeyUpMask: NSEventMask { get }
static var FlagsChangedMask: NSEventMask { get }
static var AppKitDefinedMask: NSEventMask { get }
static var SystemDefinedMask: NSEventMask { get }
static var ApplicationDefinedMask: NSEventMask { get }
static var PeriodicMask: NSEventMask { get }
static var CursorUpdateMask: NSEventMask { get }
static var ScrollWheelMask: NSEventMask { get }
static var TabletPointMask: NSEventMask { get }
static var TabletProximityMask: NSEventMask { get }
static var OtherMouseDownMask: NSEventMask { get }
static var OtherMouseUpMask: NSEventMask { get }
static var OtherMouseDraggedMask: NSEventMask { get }
static var EventMaskGesture: NSEventMask { get }
static var EventMaskMagnify: NSEventMask { get }
static var EventMaskSwipe: NSEventMask { get }
static var EventMaskRotate: NSEventMask { get }
static var EventMaskBeginGesture: NSEventMask { get }
static var EventMaskEndGesture: NSEventMask { get }
static var EventMaskSmartMagnify: NSEventMask { get }
static var AnyEventMask: NSEventMask { get }
引数
( NSUInteger )mask
マスク
Objective-C
( NSDate * )expiration
期限
Objective-C
( NSString * )mode
モード
Objective-C
( BOOL )flag
削除するかYES/NO
フレームワーク
ApplicationKit
クラス
NSApplication
使用可能
10.0
更新時のバージョン
10.10
関連記事
iOS - nextEventMatchingMaskの使い方 - Qiita
objective c - NSApp nextEventMatchingMask with dispatch inside dispatch - Stack Overflow
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { NSEvent *event; NSEvent *ev = [NSEvent mouseEventWithType:NSLeftMouseDown location:NSMakePoint(200,200) modifierFlags:NSDeviceIndependentModifierFlagsMask timestamp:0 windowNumber:[[sender window] windowNumber] context:nil eventNumber:0.0 clickCount:1 pressure:1.0 ]; event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:NO]; NSLog([event description]); [NSApp sendEvent:ev]; } @end
override func mouseDown(theEvent: NSEvent) { var newEvent: NSEvent! NSLog("start") let maskUp = NSEventMask.LeftMouseUpMask.rawValue let maskDragged = NSEventMask.LeftMouseDraggedMask.rawValue let mask = Int( maskUp | maskDragged ) // cast from UInt let anApplication = NSApplication.sharedApplication() dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { } var keepOn = true while keepOn { newEvent = anApplication.nextEventMatchingMask( Int(mask) , untilDate:(NSDate.distantPast() as NSDate), inMode:NSDefaultRunLoopMode, dequeue:true) NSLog("loop") if (newEvent != nil) { if newEvent.type == .LeftMouseUp { keepOn = false } } } dispatch_async(dispatch_get_main_queue()) { NSLog("finishLaunching") } }