制作在系统范围内侦听快捷方式的 AppleScript 程序 [英] make AppleScript program that listens systemwide for shortcuts

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

问题描述

我想创建某种后台进程来侦听所有击键事件并因此采取行动(例如,如果在 Finder.app 中按下 CMD-A 则执行某些操作,或者更复杂的事情,例如要创建的序列像 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 .. 但一无所获..
(我也很擅长 ruby​​,实际上打算使用 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)

谢谢!

推荐答案

如果你真的想捕获系统范围内的所有按键,你需要 CGEventTap.我认为 AppleScript 不能直接使用它,也许在 10.6 上您可以使用 AppleScriptObjC.当然,它应该可以通过 Bridge Support 提供给 Ruby.

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 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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