2013-10-07 48 views
14

我想在Automator中编写一个Applescript,按住左边的箭头按钮的同时按住控制,选项和命令。我到目前为止的代码是:使用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 

但是,这是行不通的。有关如何解决此问题的任何建议? 谢谢!

+0

没有ü尝试映射键盘上的Home和End按键与命令+向左或向右地图? – bicepjai

+0

仅供参考:这实际上是在尝试在所有三个修饰符中输入单词“left”。 – cabbey

回答

30

使用箭头键时,您需要通过关键代码将其定位。

tell application "Sublime Text 2" to activate 

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

ARROW键码

  • LEFT:(键码123)
  • RIGHT:关键码124)
  • UP:(键码126)
  • DOWN:(键码125)
+0

谢谢!完美工作。 – joshdon

0

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

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

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

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

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

链接: