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

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

Forwards the message to the global application object.

## Declaration

```swift
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

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

## 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:)](appkit/nswindow/nextevent(matching:).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)
