Java Swing Tutorial - Java Robot.keyPress(int keycode)








Syntax

Robot.keyPress(int keycode) has the following syntax.

public void keyPress(int keycode)

Example

In the following code shows how to use Robot.keyPress(int keycode) method.

//from  w  w w  .  j ava  2 s  .  c o  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);

  }
}