---
title: "nextEvent(matching:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nswindow/nextevent(matching:)"
---

# nextEvent(matching:)

Returns the next event matching a given mask.

## Declaration

```swift
func nextEvent(matching mask: NSEvent.EventTypeMask) -> NSEvent?
```

## Parameters

- `mask`: The mask that the event to return must match. Events with non-matching masks are left in the queue. See doc://com.apple.appkit/documentation/AppKit/NSApplication/discardEvents(matching:before:) in doc://com.apple.appkit/documentation/AppKit/NSApplication for the list of mask values.

## Return Value

Return Value The next event whose mask matches mask; nil when no matching event was found.

## Discussion

Discussion This method calls the nextEvent(matching:until:inMode:dequeue:) method, where the matching mask parameter is the specified mask, the until (Swift) or untilDate (Objective-C) parameter is distantFuture, the inMode parameter is NSEventTrackingRunLoopMode, and the dequeue parameter is true.

## See Also

### Related Documentation

- [nextEvent(matching:until:inMode:dequeue:)](appkit/nsapplication/nextevent(matching:until:inmode:dequeue:).md)

### Handling Events

- [currentEvent](appkit/nswindow/currentevent.md)
- [nextEvent(matching:until:inMode:dequeue:)](appkit/nswindow/nextevent(matching:until:inmode:dequeue:).md)
- [discardEvents(matching:before:)](appkit/nswindow/discardevents(matching:before:).md)
- [postEvent(_:atStart:)](appkit/nswindow/postevent(_:atstart:).md)
- [sendEvent(_:)](appkit/nswindow/sendevent(_:).md)
- [tryToPerform(_:with:)](appkit/nswindow/trytoperform(_:with:).md)
