Mac OS X - 如何监视窗口更改事件?
我正在开发一个 Cocoa 应用程序,它显示打开的窗口列表并突出显示当前焦点窗口。我的问题是我找不到系统通知来通知我的应用程序主(又名“聚焦”或“前景”)窗口已更改。我尝试过:
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(wsNotificationHook:) name:NSWorkspaceDidActivateApplicationNotification object:nil];
但它监视应用程序更改:当在同一应用程序内执行窗口更改时,它不会被触发(例如,如果我使用 exposè 在两个 Firefox 窗口之间传递)。是否有我可以监视的系统范围事件来跟踪主窗口的更改?
先感谢您!
I'm developing a Cocoa application that shows a list of opened windows and highlights the current focused one. My problem is that I can't find a system notification to inform my app that the main (aka "focused" or "foreground") window has changed. I tried with:
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(wsNotificationHook:) name:NSWorkspaceDidActivateApplicationNotification object:nil];
but it monitors APPLICATION change: it isn't get fired when a change of window is executed INSIDE the same application (for example, if I pass between two Firefox windows using exposè). Is there a system-wide event that I can monitor to track a change of the main window?
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将获得的最接近的可能是辅助功能 API。请参阅此处和此处对于具有(部分)解决方案的类似问题。
The closest you'll get will probably be the accessibility APIs. See here and here for similar questions with (partial) solutions.