2010-03-01 67 views
5

我想發送擊鍵到使用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

回答

0

這是開發人員的選擇,使應用程序完全知道Applescript。從Finder的角度來看,菜單項是Applescriptable,但其他UI選項可能會也可能不會。請參閱UIElementInspector以檢查可編寫腳本元素的應用程序。

+0

是否有另一種方法來模擬系統上的擊鍵? – 2010-03-04 06:08:36

0

我不能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 
7

我覺得你幾乎沒有。這是我用於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

相關問題