discardEvents(matching:before:)
Removes all events matching the given mask and generated before the specified event.
Declaration
func discardEvents(matching mask: NSEvent.EventTypeMask, before lastEvent: NSEvent?)Parameters
- mask:
Contains one or more flags indicating the types of events to discard. The constants section of the Nsevent class defines the constants you can add together to create this mask. The discussion section also lists some of the constants that are typically used.
- lastEvent:
A marker event that you use to indicate which events should be discarded. Events that occurred before this event are discarded but those that occurred after it are not.
Discussion
Use this method to ignore any events that occurred before a specific event. For example, suppose your app has a tracking loop that you exit when the user releases the mouse button. You could use this method, specifying NSAnyEventMask as the mask argument and the ending mouse-up event as the lastEvent argument, to discard all events that occurred while you were tracking mouse movements in your loop. Passing the mouse-up event as lastEvent ensures that any events that might have occurred after the mouse-up event (that is, that appear in the queue after the mouse-up event) aren’t discarded.
For the mask parameter, you can add together event type constants such as the following:
NSLeftMouseDownMaskNSLeftMouseUpMaskNSRightMouseDownMaskNSRightMouseUpMaskNSMouseMovedMaskNSLeftMouseDraggedMaskNSRightMouseDraggedMaskNSMouseEnteredMaskNSMouseExitedMaskNSKeyDownMaskNSKeyUpMaskNSFlagsChangedMaskNSPeriodicMaskNSCursorUpdateMaskNSAnyEventMask
This method can also be called in subthreads. Events posted in subthreads bubble up in the main thread event queue.