开发者

Application does not accept keystroke

开发者 https://www.devze.com 2022-12-21 18:16 出处:网络
开发者_开发问答I am trying to send keystrokes to the application VisualBoyAdvance using AppleScript, but I cannot get it to work.
开发者_开发问答

I am trying to send keystrokes to the application VisualBoyAdvance using AppleScript, but I cannot get it to work.

My code, so far, is this:

tell application "VisualBoyAdvance"
    activate

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

end tell

When I tell VisualBoyAdvance directly, I get this error:

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

I have tried telling VisualBoyAdvance directly, and I have also tried using key code 40, but I still cannot get it to work. Strangely enough, this does work:

tell application "VisualBoyAdvance"
    activate

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

end tell

But that is a keyboard shortcut that shows up in the menu bar, so I guess it would be a bit different.

How can I use AppleScript to simulate a keypress and make the application respond to it? If I cannot use AppleScript for this, what else could I use?


I think you're almost there. Here's something I used for Safari; in this example, I send key code 48 (tab).

tell application "Safari"
    activate

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

AFAICS this ought to be largely independent of AppleScript support in the target process as you're asking System Events to simulate the key press via Universal Access.

For help with key codes, see this useful application: http://manytricks.com/keycodes/


It's the developer's choice to make an application fully Applescript aware. Menu items are Applescriptable from the Finder's point of view, but other UI options may or may not be. See UIElementInspector to examine that application for scriptable elements.


I can't garuntee anything as I don't have this app but here is some things to try

 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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号