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

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

问题描述

我想响应由外部应用程序打开的某种类型的新窗口.我有一些使用某些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天全站免登陆