Create key press event using Robot class in Java

Description

The following code shows how to create key press event using Robot class.

Example


// www  .j  a va  2 s.  c om
import java.awt.Robot;
import java.awt.event.KeyEvent;

public class Main {
  public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.delay(3000);

    robot.keyPress(KeyEvent.VK_Q);
    robot.keyPress(KeyEvent.VK_W);
    robot.keyPress(KeyEvent.VK_E);
    robot.keyPress(KeyEvent.VK_R);
    robot.keyPress(KeyEvent.VK_T);
    robot.keyPress(KeyEvent.VK_Y);
  }
}




















Home »
  Java Tutorial »
    Development »




Java Algorithms
Java Clipboard
Java Compiler
Java Desktop
Java Virtual Machine
Java Math
OS
Random
Java Robot
Java RuntimeMXBean
Java Timer
Java UUID
Java Internationalization