简体   繁体   English

捕获我的 macOS 应用程序菜单栏上的点击次数

[英]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.对我来说,使用globalMonitorNSEventlocationInWindow属性似乎输出点击的坐标,即使不在应用程序的窗口上。 Here's my implementation:这是我的实现:

NSEvent.addGlobalMonitorForEvents(matching: .leftMouseDown) { event in
    print(event.locationInWindow)
}
  • As a side note, the click coordinates go from (0,0) in the bottom left of my screen to (width,height) of my screen at the top right作为旁注,点击坐标从屏幕左下角的 (0,0) 到屏幕右上角的 (width,height)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM