title: Application does not accept keystroke
body: <p>I am trying to send keystrokes to the application VisualBoyAdvance using AppleScript, but I cannot get it to work.</p>
  
  <p>My code, so far, is this:</p>
  
  <pre><code>tell application "VisualBoyAdvance"
      activate
  
      tell application "System Events"
          keystroke "k"
      end tell
  
  end tell
  </code></pre>
  
  <p>When I tell VisualBoyAdvance directly, I get this error:</p>
  
  <pre><code>error "VisualBoyAdvance got an error: Can’t get keystroke \"k\"." number -1728 from keystroke "k"
  </code></pre>
  
  <p>I have tried telling VisualBoyAdvance directly, and I have also tried using <code>key code 40</code>, but I still cannot get it to work. Strangely enough, this does work:</p>
  
  <pre><code>tell application "VisualBoyAdvance"
      activate
  
      tell application "System Events"
          keystroke "d" using {command down}
      end tell
  
  end tell
  </code></pre>
  
  <p>But that is a keyboard shortcut that shows up in the menu bar, so I guess it would be a bit different.</p>
  
  <p>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?</p>