Java Swing Tutorial - Java Robot() Constructor








Syntax

Robot() constructor from Robot has the following syntax.

public Robot()  throws AWTException

Example

In the following code shows how to use Robot.Robot() constructor.

/*w w w . j  a  va 2 s .co  m*/
import java.awt.Robot;
import java.awt.event.KeyEvent;

public class Main {
  public static void main(String[] argv) throws Exception {

    Robot robot = new Robot();

    robot.keyPress(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_A);

  }
}