views:

174

answers:

3

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?

A: 

Try this:

tell application "System Events"
tell application process "VisualBoyAdvance"
    activate
    key code {40}
end tell
end tell
Mason Rove
Nope :/ ` ` ` ` ` `
joshhunt
A: 

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.

songdogtech
Is there another way to simulate keystrokes on the system?
joshhunt
A: 

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
mcgrailm