Using Applescript to Execute a Complicated Keystroke

a 夏天 提交于 2019-12-30 02:42:07

问题


I'm trying to write an Applescript in Automator that will press the left arrow button while holding down control, option, and command. The code I have so far is:

on run {input, parameters}

    tell application "System Events"
        tell application "Sublime Text 2" to activate
        keystroke "left" using {control down, option down, command down}
    end tell

    return input
end run

However, this is not working. Any suggestions as to how to fix this code? Thanks!


回答1:


When using arrow keys you need to target them via key code.

tell application "Sublime Text 2" to activate

tell application "System Events" 
    key code 123 using {control down, option down, command down}
end tell

ARROW KEY CODES

  • LEFT: (key code 123)
  • RIGHT: key code 124)
  • UP: (key code 126)
  • DOWN: (key code 125)



回答2:


You can use any ASCII code, for the arrow keys this will be:

tell application "System Events" to keystroke (ASCII character 31) --down arrow

tell application "System Events" to keystroke (ASCII character 30) --up arrow

tell application "System Events" to keystroke (ASCII character 29) --right arrow

tell application "System Events" to keystroke (ASCII character 28) --left arrow

Links:

  • Credits

  • ASCII CODES



来源:https://stackoverflow.com/questions/19236741/using-applescript-to-execute-a-complicated-keystroke

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!