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

# nextEvent(matching:until:inMode:dequeue:)

Forwards the message to the global application object.

```
func nextEvent(matching mask: NSEvent.EventTypeMask, until expiration: Date?, inMode mode: RunLoop.Mode, dequeue deqFlag: Bool) -> NSEvent?
```

## Parameters

`mask`

The mask that the event to return must match.

`expiration`

The date until which to wait for events.

`mode`

The run loop mode to use while waiting for events

`deqFlag`

<doc://com.apple.documentation/documentation/Swift/true> to remove the returned event from the event queue; <doc://com.apple.documentation/documentation/Swift/false> to leave the returned event in the queue.

## Return Value

The next event whose mask matches the specified `mask`; otherwise, `nil`.

## 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)