Cocoa Accessibility API,我可以单击后台窗口而不激活它吗?
我一直在寻找解决这个问题的方法,所以我想我应该寻找比我更伟大的头脑。我正在开发一个 Cocoa 应用程序,它使用 Accessibility API 来操作另一个程序(它是一个热键应用程序)。我控制的应用程序通常会打开多个窗口,其中一些窗口隐藏在其他窗口后面。如果可能的话,我想做的是使用 Accessibility API 将鼠标事件发送到窗口,方式是按下窗口中的按钮而不将其带到前台(与窗口交互但不激活它) 。我尝试这样做的原因是,将鼠标事件发送到另一个窗口将迫使它到前台并中断用户与最前面的窗口的交互。
这在 Windows 上是可能的——显然,因为与我的应用程序类似的应用程序在那里做到了这一点——但我感觉这在 Cocoa 上是不可能的,考虑到窗口管理器的工作方式。我错了吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可访问性比这更高。例如,您将
AXPress
操作发送到AXButton
对象,但“按”不一定是单击 - 例如,在视图聚焦时按空格键是亦作“按”。AXPress
是一个高级操作,意味着“做你的事情”,这显然对某些视图(例如按钮)有意义,而对其他视图(例如字段)有意义。当您从其预期目的(针对残疾用户的辅助设备)来看它时,激活应用程序的辅助功能确实有意义。如果用户以任何方式“按下”某些东西,他们可能打算激活该应用程序并在其中工作。
Quartz 事件服务将让您几乎< /em> 那里:您可以 为您想要控制的进程创建一个事件点击,您可以伪造事件和将它们发送到水龙头。问题是 您只能在点击触发时向点击发送事件,即当应用程序已经有一个事件需要处理时。如果没有,你就会陷入困境。
Accessibility is higher-level than that. You send, for example,
AXPress
actions toAXButton
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.