使用Applescript执行复杂的击键

20 applescript

我正在尝试在Automator中编写一个Applescript,按住左箭头按钮,同时按住控制,选项和命令.我到目前为止的代码是:

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
Run Code Online (Sandbox Code Playgroud)

但是,这不起作用.有关如何修复此代码的任何建议?谢谢!

ada*_*amh 44

使用箭头键时,您需要通过键码来定位它们.

tell application "Sublime Text 2" to activate

tell application "System Events" 
    key code 123 using {control down, option down, command down}
end tell
Run Code Online (Sandbox Code Playgroud)

箭头键代码

  • 左:(关键代码123)
  • 右:密码124)
  • UP :(关键代码126)
  • DOWN :(关键代码125)


Lin*_*iel 5

您可以使用任何ASCII 代码,对于箭头键,这将是:

告诉应用程序“系统事件”击键(ASCII 字符 31)--向下箭头

告诉应用程序“系统事件”击键(ASCII 字符 30)--向上箭头

告诉应用程序“系统事件”击键(ASCII 字符 29)--右箭头

告诉应用程序“系统事件”击键(ASCII 字符 28)--左箭头

链接: