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

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

问题描述

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

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天全站免登陆