In following program I have use the java.awt.Robot class for generating a key press event. In following program I have use keyPress(int keyCode) method to produce this event. It is very easy process. Just try to understand it. In following program I have use keypressEG class to create key press event.
Code:
package sample.kode.jav.awt;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class keypressEG {
public static void main(String[] args) {
try {
Robot robots1 = new Robot();
robots1.delay(3560);
robots1.keyPress(KeyEvent.VK_Q);
robots1.keyPress(KeyEvent.VK_W);
robots1.keyPress(KeyEvent.VK_E);
robots1.keyPress(KeyEvent.VK_R);
robots1.keyPress(KeyEvent.VK_T);
robots1.keyPress(KeyEvent.VK_Y);
} catch (AWTException es) {
es.printStackTrace();
}
}
}
Bookmarks