获取启动应用程序/applescript时已按下的修饰键 [英] Get modifier keys, which have been pressed while starting an app / applescript

查看:75
本文介绍了获取启动应用程序/applescript时已按下的修饰键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取在启动应用程序时(尤其是Mac OS X上的ApplesScript)按下时所按下的键的列表(例如,shift键,alt,command ...).

I need to get a list of keys (e.g. the shift key, alt, command ...) which have been pressed when i started an app, especially an ApplesScript on Mac OS X.

推荐答案

迈克·伍德菲尔(Mike Woodfill)的简短回答:

A shorter form of Mike Woodfill's answer:

set {shiftDown, ctrlDown, altDown, cmdDown} to words of (do shell script "python -c 'import Cocoa;m=Cocoa.NSEvent.modifierFlags();print m&Cocoa.NSShiftKeyMask>0,m&Cocoa.NSControlKeyMask>0,m&Cocoa.NSAlternateKeyMask>0,m&Cocoa.NSCommandKeyMask>0'")

请注意,您将修饰符作为字符串获取,因此必须像这样if (altDown = "True") then ...

Note, that you get the modifiers as strings, so you have to compare them like this if (altDown = "True") then ...

如果您确实需要布尔修饰符,请查看以下代码:

If you really want boolean modifiers, look at this code:

set mods to {}
repeat with m in words of (do shell script "python -c 'import Cocoa;m=Cocoa.NSEvent.modifierFlags();print m&Cocoa.NSShiftKeyMask,m&Cocoa.NSControlKeyMask,m&Cocoa.NSAlternateKeyMask,m&Cocoa.NSCommandKeyMask'")
    set end of mods to m as number as boolean
end repeat
set {shiftDown, ctrlDown, altDown, cmdDown} to mods

这篇关于获取启动应用程序/applescript时已按下的修饰键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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