Cocoa可访问性API,我可以在后台点击一个窗口而不激活它吗? [英] Cocoa accessibility API, can I click a window in the background without activating it?

查看:232
本文介绍了Cocoa可访问性API,我可以在后台点击一个窗口而不激活它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个解决方案,所以我想我会找到更大的心灵的智力比我的。我正在开发一个Cocoa应用程序,使用辅助功能API来操纵另一个程序(它是一个热键应用程序)。我控制的应用程序通常有多个窗口打开,一些隐藏在别人后面。我想做的,如果可能,是使用辅助功能API发送鼠标事件到窗口,按下窗口中的按钮,而不将其带到前台(与窗口交互,但不激活它) 。我试图这样做的原因是发送鼠标事件到这个其他窗口将会强制它到前台,并中断用户与最前面的窗口的交互。



这在Windows上是可能的 - 显然,因为类似于我的应用程序在那里 - 但我得到的感觉,这是不可能与Cocoa,方式窗口管理器工作。我错了吗?

解决方案

辅助功能比这更高级。例如,您将 AXPress 操作发送到 AXButton 对象,但按不一定是点击空间条,而视图被聚焦,例如,也是一个按下。 AXPress 是一种高级操作,意味着做你的事,这显然对某些视图(如按钮)有意义,而不是其他(如字段)。 / p>

辅助功能激活应用程序确实有意义,当您从它的预期目的:辅助设备为残疾用户。如果用户通过任何方式按下某些东西,他们可能打算激活应用程序并在其中工作。



Quartz事件服务会让你几乎:你可以创建事件点击您想要控制的过程,并且您可以伪造事件和将其发送到点击。抓住的是您只能在触发点击时将事件发送到点按 - 即当应用程序已经有一个事件要处理时。如果没有,你就会被困住。


I've been searching forever for a solution to this, so I thought I'd seek out the brainpower of greater minds than mine. I'm developing a Cocoa app that uses the Accessibility API to manipulate another program (it's a hotkey app). The app I'm controlling typically has multiple windows open, with some hidden behind others. What I would like to do, if it's possible, is to send mouse events to windows using the Accessibility API in a way that presses a button in the window without bringing it to the foreground (interact with the window but don't activate it). The reason I'm trying to do this is that sending the mouse event to this other window will force it to the foreground and disrupt the user's interaction with the foremost window.

This is possible on Windows - apparently, because apps similar to mine do it there - but I'm getting the feeling that this isn't possible with Cocoa, given the way the window manager works. Am I mistaken?

解决方案

Accessibility is higher-level than that. You send, for example, AXPress actions to AXButton objects, but "press" is not necessarily a click—pressing the space bar while a view is focused, for example, is also a "press". AXPress is a high-level action that means "do your thing", which obviously has meaning for some views (such as buttons) and not others (such as fields).

Accessibility activating the application does make sense when you look at it from its intended purpose: Assistive devices for disabled users. If the user "presses" something by whatever means, they probably intend to activate the application and work in it.

Quartz Event Services will get you almost there: You can create an event tap for the process you want to control, and you can forge events and send them to a tap. The catch is that you can only send events to a tap when the tap fires—i.e., when the application already has an event to deal with. When it doesn't, you're stuck.

这篇关于Cocoa可访问性API,我可以在后台点击一个窗口而不激活它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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