[英]Capture clicks on menu bar for my macOS app
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
我也无法使用
addGlobalMonitorForEvents
为我的应用程序捕获菜单栏点击
NSEvent.addLocalMonitorForEvents(matching: .leftMouseDown , handler: {
(mouseEvent:NSEvent?) in ....
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.对我来说,使用
globalMonitor
和NSEvent
的locationInWindow
属性似乎输出点击的坐标,即使不在应用程序的窗口上。 Here's my implementation:这是我的实现:
NSEvent.addGlobalMonitorForEvents(matching: .leftMouseDown) { event in
print(event.locationInWindow)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.