[QUESTION] Java: input keystrokes to other program?

09/23/2012 13:50 strontklit#1
Hi,

I was wondering if i program a GUI and everything in java so that i can make keys get repeated multiple times (to create a bot) which i can do so far, is there a way to input these keystrokes to another program (a game)?

I am not asking how to program all the rest just if there is a way to input it?

I hope someone can help me. I prefer english answers but i can read german too just not write it :p

Thanks in advance
09/23/2012 14:00 Obilee#2
Switch the focus to the game window and repeat the keys with the robot class:

Code:
 Robot robot = new Robot();
            // Creates the delay of 5 sec so that you can open notepad before
            // Robot start writting
            robot.delay(5000);
            robot.keyPress(KeyEvent.VK_H);
            robot.keyPress(KeyEvent.VK_I);
            robot.keyPress(KeyEvent.VK_SPACE);
            robot.keyPress(KeyEvent.VK_B);
            robot.keyPress(KeyEvent.VK_U);
            robot.keyPress(KeyEvent.VK_D);
            robot.keyPress(KeyEvent.VK_Y);