Java program to
automate keyboard key press and mouse click events
import java.awt.AWTException; import java.awt.Robot; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; public class Test { public static void main(String[] args){ try { Robot robot = new Robot(); robot.mouseMove(100, 100); robot.mouseMove(400, 200); // Simulate a mouse click robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_ALT); robot.keyRelease(KeyEvent.VK_TAB); // Simulate a key press while(true){ Thread.sleep(2000); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A); } } catch (AWTException e) { e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }