Mac/Cocoa - 使用 Accessibility API 获取窗口列表 [英] Mac / Cocoa - Getting a list of windows using Accessibility API

查看:36
本文介绍了Mac/Cocoa - 使用 Accessibility API 获取窗口列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用辅助功能 API 来获取给定应用程序(外部)的所有窗口列表.

I want to use the Accessibility API to get a list of all windows for a given application (external).

目标是检查某个窗口是否打开.首先我检查应用程序是否正在运行(使用 [NSWorkspace runningApplications] 并检查每个),然后我想检查为该应用程序打开的每个窗口的标题栏文本.

The goal is to check if a certain window is open. First I check that the application is running (using [NSWorkspace runningApplications] and checking each one), and then I want to check the title bar text of each window that is open for that application.

附注

所以我可以使用 PID 为应用程序创建一个元素:

So I can create an element for the app using the PID:

AXUIElementRef app = AXUIElementCreateApplication(pid);

但是我该怎么办呢?我什至朝着正确的方向前进吗?无法相信很难找到这方面的例子.

but what do I do with it? Am I even going in the right direction? Can't beleive it's so hard to find examples on this.

推荐答案

使用 AXUIElementCopyAttributeValues 复制 kAXWindowsAttribute 的值,它应该是一个 AXUIElement 对象数组,表示应用程序的窗口.

Use AXUIElementCopyAttributeValues to copy the value for kAXWindowsAttribute, which should be an array of AXUIElement objects representing the application's windows.

从它的函数名可以猜到,它遵循复制规则.

As you can guess from its function name, it follows the copy rule.

这篇关于Mac/Cocoa - 使用 Accessibility API 获取窗口列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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