窗口列表按最近使用排序
我正在尝试创建一个窗口切换应用程序。有没有办法获取其他应用程序的窗口列表(按最近使用的顺序排列)?
I'm trying to create a window switching application. Is there any way of getting a list of the windows of other applications, ordered by recently used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从辅助功能框架开始。许多屏幕阅读器的挂钩在这里也很有用。特别查看 UIElementInspector 示例和 NSAccessiblity 协议。
还有 Quartz Window 服务,它可以轻松地为您提供屏幕上所有窗口的列表。不幸的是,它与窗口焦点(只是级别)等概念没有联系,而且我不知道当级别发生变化时如何从中获取通知。您可能会执行一些操作,例如进入 Quartz 事件框架来捕获 Cmd-Tab 等,但这是复杂且脆弱的。不幸的是没有好的方法将 CGWindowID 转换为AXUIElementRef(这篇文章适用于 10.5,但我不知道 10.6 中添加了任何内容来改进这一点)。但希望您可以通过辅助功能框架完成您需要的一切。
Start with the Accessibility framework. Many of the hooks for screen readers are also useful here. Particularly look at the UIElementInspector sample and the NSAccessiblity protocol.
There's also Quartz Window services, which can easily give you a list of all the windows on screen. Unfortunately, it doesn't tie into concepts like window focus (just level), and I don't know of a way to get notifications back from it when levels change. You might do something like tap into the Quartz Event framework to capture Cmd-Tab and the like, but that's complex and fragile. There is unfortunately no good way to convert a CGWindowID into an AXUIElementRef (the post is for 10.5, but I don't know of anything that was added in 10.6 to improve this). But hopefully you can do everything you need through the Accessibility framework.
您可能希望使用
它来获取所有正在运行的应用程序的列表,并观察
以了解用户何时切换到新应用程序,以了解最近使用的应用程序。
You would want to use
to get you a list of all the applications running, and watch
to know when the user switches to a new application to keep up with which one is used more recently.