问题描述
创建半透明窗口后()我想在这个窗口中获得键盘事件。看来,当我的应用程序是活动应用程序时,只有键盘事件,而我想要键盘事件,即使我的应用程序没有活动但窗口是可见的。
After creating a translucent window (based on example code by Matt Gemmell) I want to get keyboard events in this window. It seems that there are only keyboard events when my application is the active application while I want keyboard events even when my application isn't active but the window is visible.
基本上我想要类似Quicksilver应用程序(由blacktree提供)的行为。
Basically I want behavior like that provided by the Quicksilver application (by blacktree).
有没有人有任何提示如何做?
Does anybody have any hints on how to do this?
推荐答案
有两个选项:
- 使用与一个粘连的碳运行循环来抓取键盘事件。示例代码位于CocoaDev的。
- 使用。示例代码可以在中找到苹果开发者邮件列表。
- Use
GetEventMonitorTarget()
with a tacked-on Carbon run loop to grab keyboard events. Sample code is available on this page at CocoaDev. - Register an event trap with
CGEventTapCreate
. Sample code can be found in this thread from the Apple developer mailing list.
编辑:请注意,只有在通用存取偏好设定中勾选[启用辅助装置的存取权]
Note that these methods only work if you check off "Enable access for assistive devices" in the Universal Access preference pane.
这篇关于如何在NSStatusWindowLevel窗口中获取键盘事件,而我的应用程序不是最前面的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!