Java bot for an online game
First of all, most games have bot protection, so make sure to add a delay to the bot and, maybe, a 'cooldown'. Before that r.delay(1000)
statement, the bot did two instant actions.
I'm almost sure it's not working because the keystrokes are way too fast: they press and release instantly. Try adding bot.delay(500)
(or more, depends on the game) right after you instantiate Robot class; before all the key pressing functions. That would add a 500ms delay between ALL actions done by the robot.
public static void doStuff() {
Robot r = new Robot();
r.delay(500); //Or more - depends on the game
r.keyPress(KeyEvent.VK_Z);
r.keyRelease(KeyEvent.VK_Z);
r.keyPress(KeyEvent.VK_1);
System.out.println("Press 1 button");
r.keyRelease(KeyEvent.VK_1);
System.out.println("Release 1 button");
r.delay(1000);
System.out.println("Move mouse");
r.mouseMove(110, 690);
System.out.println("Press");
r.mousePress(InputEvent.BUTTON3_MASK);
System.out.println("Release");
r.mouseRelease(InputEvent.BUTTON3_MASK);
}
I think the only reason why the Z and 1 keys didn't work was the speed everything was done. The game probably has an anti-bot system.