5

I am trying to send keyboard commands to a game emulator from my Java program, I know how to set up the process from processbuilder and run the process.

However, I'm still having trouble with sending the process keyboard commands from my Robot.

An InputStream won't be much help as I need to send keyEvents such as pressing the 'y' button and having the emulator respond accordingly.

eltabo
  • 3,749
  • 1
  • 21
  • 33
Bskogen
  • 51
  • 3

1 Answers1

0

You need your application/console window to be the active window for the key presses to be sent there. I suggest as a first test, run your java app but add a 10 second delay before starting the key presses. Then, click manually and activate the emulator window and wait for the automated key presses to start.

Also, add a 500 MS delay between key presses (e.g. using Thread.sleep() ) because multiple key presses do not work well.

Also See: Using Java to set the focus to a non Java application in Windows

Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155