如何接收新窗口打开的通知? [英] How do I receive notification of a new window opening?

查看:32
本文介绍了如何接收新窗口打开的通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想响应外部应用程序打开的某种类型的新窗口.我有一些使用一些 carbon 功能查找当前打开的应用程序和窗口(系统范围内)的经验,因此理论上可以每隔几秒钟检查一次.这需要获取所有打开的窗口的列表,并根据我必须维护的某个列表进行检查,并且感觉非常笨重.

I want to respond to a certain type of new window being opened by an external application. I have some experience finding applications and windows currently open (system wide) using some of the carbon functionality, so could theoretically just check every few seconds. This would require getting a list of all open windows and checking it against some list I would have to maintain, and feels very clunky.

如何在启动新窗口时获得简单、干净的通知?我应该使用辅助功能 API 吗?如果是这样,我要特别寻找什么?

How can I get a simple, clean notification when a new window is launched? Should I use the accessibility API? If so, what specifically am I looking for?

推荐答案

首先,创建一个 AXObserver.然后,观察您认为您会感兴趣的任何应用程序的启动.当这样的启动发生时,为该进程创建一个应用程序 AXUIElement,并将您的观察者添加到它以接收 kAXWindowCreatedNotification 通知.

First, create an AXObserver. Then, watch for launches of any applications that you think you'd be interested in. When such a launch occurs, create an application AXUIElement for that process, and add your observer to it for the kAXWindowCreatedNotification notification.

我怀疑这是否是做您想做的任何事情的最佳方式.您可能会从这个解决方案中退一步(即注意新窗口)并询问有关您的目标的另一个问题.

I question whether this is the best way to do whatever you're trying to do. You might step back a bit from this solution (that is, watching for new windows) and ask another question about your goal.

这篇关于如何接收新窗口打开的通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆