应用程序不接受按键

问题描述:

我想发送击键到使用AppleScript的应用程序VisualBoyAdvance,但我无法让它工作。应用程序不接受按键

我的代码,到目前为止,是这样的:

tell application "VisualBoyAdvance" 
    activate 

    tell application "System Events" 
     keystroke "k" 
    end tell 

end tell 

当我直接告诉VisualBoyAdvance,我得到这个错误:

error "VisualBoyAdvance got an error: Can’t get keystroke \"k\"." number -1728 from keystroke "k" 

我曾尝试直接告诉VisualBoyAdvance了,我也试着使用key code 40,但我仍然无法使其工作。奇怪的是,这样做的工作:

tell application "VisualBoyAdvance" 
    activate 

    tell application "System Events" 
     keystroke "d" using {command down} 
    end tell 

end tell 

但是,这是一个快捷键,在菜单栏上显示出来,所以我想这将是一个有点不同。

如何使用AppleScript模拟按键并使应用程序响应它?如果我不能为此使用AppleScript,还可以使用其他什么?

+0

你有辅助设备支持打开? – alesplin 2010-03-02 19:41:47

+0

这有什么好运? – 2014-04-18 01:57:59

这是开发人员的选择,使应用程序完全知道Applescript。从Finder的角度来看,菜单项是Applescriptable,但其他UI选项可能会也可能不会。请参阅UIElementInspector以检查可编写脚本元素的应用程序。

+0

是否有另一种方法来模拟系统上的击键? – 2010-03-04 06:08:36

我不能garuntee什么,因为我没有这个程序,但这里是一些事情要尝试

tell application "VisualBoyAdvance" 
    activate 
    tell application "System Events" 
     tell application process "VisualBoyAdvance" 
      try 
      keystroke "k" 
       on error 
        try 
        keystroke (ASCII character 75) 
        end try 
       end try 
     end tell 
    end tell 
end tell 

我觉得你几乎没有。这是我用于Safari的东西;在这个例子中,我发送密钥代码48(选项卡)。

tell application "Safari" 
    activate 

    tell application "System Events" to tell process "Safari" to key code 48 
end tell 

这应该作为AFAICS你问系统事件模拟通过普及的按键在很大程度上是独立的目标进程AppleScript的支持。

对于关键代码的帮助,请参阅本有用的应用:http://manytricks.com/keycodes/

+0

另外:'告诉应用程序“系统事件”告诉进程“Safari”按键“d”# – frnhr 2016-01-20 19:42:50

+0

尼斯@frnhr - 这更清晰:) – 2016-01-27 20:26:57