key down命令不适用于常规键

时间:2016-01-26 15:49:17

标签: applescript key

假设我想按“c”键5秒然后释放它。这就是我想要做的事情:

tell application "System Events"
    key down "c"
    delay 5
    key up "c"
end tell

但它不起作用。无论信件如何,它总是按“a”。我甚至尝试使用密钥代码8(相当于c),但它也不起作用。

1 个答案:

答案 0 :(得分:0)

您应该使用命令keystroke。所以代码看起来像这样:

tell application "System Events"
    set fiveSecondsFromNow to (time of (current date)) + 5
    repeat until (time of (current date)) is fiveSecondsFromNow
        keystroke "c"
    end repeat
end tell