I'm currently taking in a nextEvent within my mouseDrag function
while true {
guard let nextEvent = self.window?.nextEvent(matching: [.leftMouseDragged, .leftMouseUp, .rightMouseUp]) else {
continue
}
switch nextEvent.type {
case .leftMouseDragged:
self.cursorUpdate(with: nextEvent)
self.mouseDragged(with: nextEvent)
case .rightMouseUp:
continue
default:
self.mouseUp(with: nextEvent)
return
}
}
And I'm just trying to disable right click for the duration. However, with this implementation the right clicks simply queue up and get called after the loop finishes.
How would I disable right clicks being registered at all?
Try adding
.rightMouseDownand.rightMouseDraggedto your matching mask. It is the.rightMouseDownevent that makes AppKit display the context menu.You might also consider switching to
NSWindow.trackEvents(matching:timeout:mode:handler:)instead of writing your own loop:Using
trackEventslets AppKit run the main run loop, so timers and observers can continue firing (if they are scheduled for.eventTrackingRunLoopMode).