<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWindow/nextEvent(matching:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSWindow(im)nextEventMatchingMask:"
  },
  "title" : "nextEvent(matching:)"
}
-->

# nextEvent(matching:)

Returns the next event matching a given mask.

```
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 [`discardEvents(matching:before:)`](/documentation/AppKit/NSApplication/discardEvents(matching:before:)) in [`NSApplication`](/documentation/AppKit/NSApplication) for the list of mask values.

## Return Value

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

## Discussion

This method calls the [`nextEvent(matching:until:inMode:dequeue:)`](/documentation/AppKit/NSWindow/nextEvent(matching:until:inMode:dequeue:)) method, where the matching mask parameter is the specified `mask`, the `until` (Swift) or `untilDate` (Objective-C) parameter is <doc://com.apple.documentation/documentation/Foundation/NSDate/distantFuture>, the `inMode` parameter is [`NSEventTrackingRunLoopMode`](/documentation/AppKit/NSEventTrackingRunLoopMode), and the `dequeue` parameter is <doc://com.apple.documentation/documentation/Swift/true>.

## See Also

[`nextEvent(matching:until:inMode:dequeue:)`](/documentation/AppKit/NSApplication/nextEvent(matching:until:inMode:dequeue:))

Returns the next event matching a given mask, or `nil` if no such event is found before a specified expiration date.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)