I have the following code for listening for mouse events outside the view (subclass of NSView). This works great as it is, but I cannot figure out how to pipe the NSEventMasks together. I basically want to have the same event listener fire on NSEventMask.LeftMouseDownMask
, NSEventMask.RightMouseDownMask
and NSEventMask.OtherMouseDownMask
.
Does anyone know how to pipe them together or if it's even possible in Swift?
Working code
localMouseEventListener = NSEvent.addLocalMonitorForEventsMatchingMask(NSEventMask.LeftMouseDownMask) { (event: NSEvent) -> NSEvent? in
// Event handling...
return event
}
This answer might help you.
In short you can now use arrays, so this seems to make the compiler happy:
localMouseEventListener = NSEvent.addLocalMonitorForEventsMatchingMask([.LeftMouseDownMask, .RightMouseDownMask, .OtherMouseDownMask]) { (event: NSEvent) -> NSEvent? in
// Event handling...
return event
}