简体   繁体   English

可可/目标c:如何知道光标所在的控件?

[英]cocoa / objective c : How to know which control is under the cursor?

I am making an application which will detect global mouse events and log the action performed. 我正在制作一个将检测全局鼠标事件并记录所执行操作的应用程序。

For example : If i click on close/minimize button on finder(or any other app like firefox,safari etc) then the app should be able to detect this. 例如:如果我单击查找器上的关闭/最小化按钮(或其他任何应用程序,如firefox,safari等),则该应用程序应该能够检测到。 Till now i could find the window name under the cursor when click is made. 到目前为止,单击时我可以在光标下找到窗口名称。 So i can capture mouse click events. 这样我就可以捕获鼠标单击事件。 But i am not able to find on how to detect exact which button/control was clicked on that window. 但是我无法找到有关如何准确检测在该窗口上单击了哪个按钮/控件的信息。

I am using NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDownMask| NSRightMouseDownMask ) handler:^(NSEvent *event){ } for capturing mouse events. 我正在使用NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDownMask| NSRightMouseDownMask ) handler:^(NSEvent *event){ }来捕获鼠标事件。

So Is there a way i could know which button/control was clicked? 因此,有什么办法可以让我知道单击了哪个按钮/控件? Or in case a folder icon is clicked on finder then is there a way to know that selected folder name. 或者,如果在查找器上单击了文件夹图标,则有办法知道所选的文件夹名称。

Thanks in advance! 提前致谢!

Its simple. 这很简单。 Check UIElementInspector example in dev.apple.com mac library. 查看dev.apple.com Mac库中的UIElementInspector示例。 Following is the link: 以下是链接:

https://developer.apple.com/library/mac/#samplecode/UIElementInspector/Introduction/Intro.html https://developer.apple.com/library/mac/#samplecode/UIElementInspector/Introduction/Intro.html

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

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