Reputation: 4632
Below statement captures all clicks inside my app window but does not capture the clicks on the menu bar for my app. I am also unable to capture menu bar click for my app using addGlobalMonitorForEvents
NSEvent.addLocalMonitorForEvents(matching: .leftMouseDown , handler: {
(mouseEvent:NSEvent?) in ....
Upvotes: 1
Views: 263
Reputation: 3400
For me, using the globalMonitor
along with NSEvent
's locationInWindow
property seemed to output coordinates of the click, even when not on the window of the app. Here's my implementation:
NSEvent.addGlobalMonitorForEvents(matching: .leftMouseDown) { event in
print(event.locationInWindow)
}
Upvotes: 2