Application does not accept keystrokes

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

My code is still like this:

tell application "VisualBoyAdvance"
    activate

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

end tell

When I say VisualBoyAdvance directly, I get this error:

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

I tried to pass VisualBoyAdvance directly, and I also tried using key code 40, but I still can't get it to work. Oddly enough, this works:

tell application "VisualBoyAdvance"
    activate

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

end tell

But this is the key combination that appears in the menu bar, so I assume it will be a little different.

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

+5
3

, . Safari; key code 48 ().

tell application "Safari"
    activate

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

AFAICS AppleScript , System Events Universal Access.

. : http://manytricks.com/keycodes/

+7

, Applescript. Finder, . . UIElementInspector, .

0

I can’t use anything because I don’t have this application, but here are 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
source

All Articles