如何在NSStatusWindowLevel窗口中获取键盘事件,而我的应用程序不是最前面的? [英] How do I get keyboard events in an NSStatusWindowLevel window while my application is not frontmost?

查看:126
本文介绍了如何在NSStatusWindowLevel窗口中获取键盘事件,而我的应用程序不是最前面的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建半透明窗口后(基于示例代码Matt Gemmell )我想在这个窗口中获得键盘事件。看来,当我的应用程序是活动应用程序时,只有键盘事件,而我想要键盘事件,即使我的应用程序没有活动但窗口是可见的。

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?

推荐答案

有两个选项:


  1. 使用 GetEventMonitorTarget() 与一个粘连的碳运行循环来抓取键盘事件。示例代码位于CocoaDev的此页面


  2. 使用 CGEventTapCreate 。示例代码可以在此主题中找到苹果开发者邮件列表。
  1. Use GetEventMonitorTarget() with a tacked-on Carbon run loop to grab keyboard events. Sample code is available on this page at CocoaDev.

  2. 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窗口中获取键盘事件,而我的应用程序不是最前面的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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