Here I try to write a simple code, which write some text on a text editor and then close the editor without saving the file. Many things are hard coded in this example, like
robot.mouseMove(1420,20); // this is my desktop close button place in full screen mode.
So, if you want to run this code, just change this line according to your desktop. After changing run this code, open any editor say notepad within 10 seconds and then this example will write some text on it and then it will close the window.
import java.awt.Robot;
import java.awt.event.*;
public class MainClass {
public static void main(String[] args) throws Exception{
Robot robot = new Robot();
// giving you 10 sec to open any text editor.
robot.delay(10000);
robot.keyPress(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_E);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_T);
robot.mouseMove(1420,20);
robot.mousePress( InputEvent.BUTTON1_MASK );
robot.mouseRelease( InputEvent.BUTTON1_MASK );
Thread.sleep(50);
robot.mousePress( InputEvent.BUTTON1_MASK );
robot.mouseRelease( InputEvent.BUTTON1_MASK );
robot.delay(1000);
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);
}
}
This is some useless example, but one can thing of some good examples but using this class.
public static void main(String[] args) throws Exception{
Robot robot = new Robot();
// giving you 10 sec to open any text editor.
robot.delay(10000);
robot.keyPress(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_H);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_I);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_SPACE);
robot.keyPress(KeyEvent.VK_T);
robot.keyPress(KeyEvent.VK_E);
robot.keyPress(KeyEvent.VK_S);
robot.keyPress(KeyEvent.VK_T);
robot.mouseMove(1420,20);
robot.mousePress( InputEvent.BUTTON1_MASK );
robot.mouseRelease( InputEvent.BUTTON1_MASK );
Thread.sleep(50);
robot.mousePress( InputEvent.BUTTON1_MASK );
robot.mouseRelease( InputEvent.BUTTON1_MASK );
robot.delay(1000);
robot.keyPress(KeyEvent.VK_TAB);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);
}
}
This is some useless example, but one can thing of some good examples but using this class.