Monday, August 23, 2010

Java Robot Class in Java

This is a quick snap of using Robot class of Java. You can find full article on keyboard and mouse events here.
package test;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

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

       int keyEvent[] = {
            KeyEvent.VK_H,
            KeyEvent.VK_E,
            KeyEvent.VK_L,
            KeyEvent.VK_L,
            KeyEvent.VK_O,
            
        };
       for(int i = 0; i < keyEvent.length; i++)
       {
          robot.keyPress(keyEvent[i]);
          robot.delay(1000);
       }

    }
}

1 comment: