使AppleScript程序在全系统范围内侦听快捷方式

使AppleScript程序在全系统范围内侦听快捷方式

本文介绍了使AppleScript程序在全系统范围内侦听快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一些后台进程来监听所有的击键事件和行为(例如,如果CMD-A在Finder.app中被按下,或者更复杂的事情,如序列创建快捷键如emacs ..)

I'd like to create some kind of background process that listens to all keystrokes event and acts consequently (for example does some action if CMD-A is pressed while in Finder.app, or more complex things, like sequences to create shortcuts like in emacs..)

但是,如何在SnowLeopard系统范围内收听按键?
我想到了Applescript ..但没有发现任何东西..

(我也很好,而且打算使用rb-appscript)

But how can I listen to keypresses systemwide on SnowLeopard?I thought of Applescript.. but found nothing..
(I'm good at ruby too, and intended to use rb-appscript actually)

谢谢!

推荐答案

如果您真的想捕获系统范围内的所有按键,则需要。

If you really want to capture all the keystrokes system-wide, you need CGEventTap. I don't think it's available directly to AppleScript, maybe on 10.6 you can use AppleScriptObjC. Surely it should be available to Ruby via Bridge Support.

然而,系统范围的键盘监听器将被非常频繁地调用。我建议在C或Obj-C中编写代码,这将更有效。

However, a system-wide keyboard listener would be called very often. I would suggest to code in C or Obj-C instead, which would be more efficient.

这篇关于使AppleScript程序在全系统范围内侦听快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:10