没有启用帮助时的热键CGEventTap [英] Hotkey when no assistance enabled CGEventTap

查看:96
本文介绍了没有启用帮助时的热键CGEventTap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用过addLocal,它可以在我的应用程序中运行,但是我想全局监视,所以我尝试了addGlobalMonitorForEventsMatchingMask:handler:,但是NSEventKeyDown根本没有被触发.显然,它需要启用辅助权限.

I had used addLocal and it would work in my application, but I want to watch globally so i tried addGlobalMonitorForEventsMatchingMask:handler: but NSEventKeyDown is not getting triggered at all. Apparently it needs assistive permission enabled.

我能够全局观看NSScrollWheel事件.哪个有趣.

I am able to watch NSScrollWheel events globally. Which is interesting.

在我花很多时间进入希望遇到的障碍之前,使用CGEventTap来监视关键事件是否在全局上工作而无需打开辅助功能?

Before I put a bunch of time into and come to same roadblock I was hoping to ask first, would using CGEventTap to monitor key events work globally without assitive turned on?

https://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/index.html#//apple_ref/c/tdef/CGEventTapLocation

我还将探索其他方法,但是(对于学习)我非常好奇CGEventTap是否可以在全球范围内正常工作.他似乎在暗示这可能可行,但评论显示出一些困惑: https://stackoverflow.com/a/9345536/1828637

I will also explore other methods but was very curious (for learning) about if CGEventTap will work globally no problems. He seems to hint here that it may work but the comments show some confusion: https://stackoverflow.com/a/9345536/1828637

我还将使用Carbon API的其他方法.

Other methods I am going to use also Carbon APIs.

推荐答案

CGEventTap对辅助设备的权限需要与全局事件监视器相同的访问权限.从CGEventTapCreate()的文档中:

A CGEventTap requires the same access for assistive devices permissions as a global event monitor. From the documentation for CGEventTapCreate():

如果满足以下任一条件,则事件分接头将接收按键上升和按键下降事件 条件成立:

Event taps receive key up and key down events if one of the following conditions is true:

  • 当前进程以root用户身份运行.

  • The current process is running as the root user.

启用了对辅助设备的访问.在OS X v10.4中,您可以使用系统偏好设置",通用访问"面板, 键盘视图.

Access for assistive devices is enabled. In OS X v10.4, you can enable this feature using System Preferences, Universal Access panel, Keyboard view.

我建议使用旧的Carbon RegisterEventHotKey()机制.它仍然不被弃用,并且可用于64位.这与许多碳相反.基本上,Apple意识到还没有适当的替代品.

I recommend using the old Carbon RegisterEventHotKey() mechanism. It still isn't deprecated and is available for 64-bit. This is in contrast to much of Carbon. Basically, Apple recognizes that there's no proper replacement, yet.

这篇关于没有启用帮助时的热键CGEventTap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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