它不是通過更多鈔票AppleScript中用戶檢測按鍵。你可以通過編程按鍵。要解決按住某個按鍵的問題,請使用「按鍵」命令並在需要釋放時發出「按鍵」命令。這將適用於任何應用程序。這是一個例子。
tell application "KeyboardViewer" to activate
tell application "System Events"
try --don't even consider not using a try block because down keys can get stuck!
key down control
delay 1
key down shift
delay 1
key down option
delay 1
key down command
delay 1
key up control
delay 1
key up shift
delay 1
key up option
delay 1
key up command
delay 1
key down {control, shift, option, command}
delay 1
key up {control, shift, option, command}
on error --logging out is the only other way to unstick these
key up {control, shift, option, command}
end try
end tell
tell application "KeyboardViewer" to quit
注意:如果您想按順序按下並釋放某些按鍵,也可以使用「keystroke」命令。例如要按命令,您可以執行以下操作:
tell application "System Events"
keystroke "s" using command down
end tell
感謝您的回答,我會明天嘗試並接受此答案是否有效。看起來非常合乎邏輯,但我現在要走了。 – FLY
我收到錯誤KeyboardViewer找不到 – FLY
試試這個在它的地方。我在10.8上,但在早期版本中,它被稱爲... KeyboardViewerServer.app。 – regulus6633