以编程方式启用对辅助设备的访问
我想以编程方式在系统偏好设置中启用对辅助设备的访问。但问题是我的应用程序没有以 root 用户身份运行,我不希望我的应用程序以 root 用户身份运行,也不应该要求其间进行任何身份验证。
我想点击全球所有键盘事件。我正在使用 CGEventTapCreate() 进行相同的操作。在 CGEventTapCreate() API 的文档中提到,如果满足以下条件之一,事件点击会接收按键向上和按键向下事件:
- 当前进程正在以根用户身份运行。
- 已启用辅助设备的访问。在 Mac OS X v10.4 和稍后,您可以使用系统偏好设置、通用访问面板、键盘视图启用此功能。
我通过检查“系统偏好设置”中的“启用辅助设备的访问”来手动尝试,它给了我预期的输出。
那么有没有什么方法可以通过程序执行相同的操作而不要求身份验证并且应用程序不以 root 用户身份运行?
谢谢,
黛拉吉。
I want to enable Access for assistive devices in System Preferences programmatically. But Problem is that my application is not running as root user and i do not want my application to be as root user and also should not ask for any authentication in between.
I want to tap all keyboard events globally. I am using CGEventTapCreate() for the same.In the documentation of CGEventTapCreate() API it is mentioned that, Event taps receive key up and key down events if one of the following conditions is true:
- The current process is running as the root user.
- Access for assistive devices is enabled. In Mac OS X v10.4 & later, you can enable this feature using System Preferences, Universal Access panel, Keyboard view.
I tried manually by checking the Enable Access for assistive devices from System Preference and it gives me expected output.
So is there any way to do the same via program without asking for authentication and also application is not running as root user?
Thanks,
Dheeraj.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以运行 Applescript(或将 Applescript 转换为 ScriptingBridge 或 AppleEvents 上的任何 Objective-C 层)
以下是我在一个特定项目中使用的 Applescript,它执行与您需要的类似操作:
You can run an Applescript (or translate the Applescript into ScriptingBridge or whatever your Objective-C layer over AppleEvents is)
Here is an Applescript that I use in one particular project that does something similar to what you need:
好的,解决方案/一些背景信息 可以在这个地址找到..
Ok y'all the solution / some background info can be found at this address..
如果没有明确请求许可,则在不至少告知用户的情况下更改用户的系统设置通常被认为是粗鲁的。大多数需要此设置的应用程序只需检查它是否启用,如果没有,则告诉用户将其打开。
It's usually considered rude to change a user's system setting without at least telling them, if not explicitly asking for permission. Most apps that need this setting just check to see if it's enable and if not, tell the user to turn it on.
您确定可以在每个进程的基础上启用它,而不需要管理员权限?如果是,是捕获所有事件,还是仅捕获属于该进程的事件?
Are you sure that it's possible to enable it on a per-process basis, without needing to have admin rights? And if yes, will all events be captures, or only the ones belonging to the process?