Created
November 6, 2013 15:53
-
-
Save madan712/7338528 to your computer and use it in GitHub Desktop.
Example using Java.awt.Robot class. In this example we will open a notepad and type a message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.AWTException; | |
| import java.awt.Robot; | |
| import java.awt.event.KeyEvent; | |
| public class TestRobot { | |
| private Robot robot; | |
| private static final int SPEED = 300; | |
| private void execute(int[] letter){ | |
| try { | |
| robot = new Robot(); | |
| } catch (AWTException e) { | |
| e.printStackTrace(); | |
| } | |
| for (int i = 0;i<letter.length ;i++ ) { | |
| robot.delay(SPEED); | |
| robot.keyPress(letter[i]); | |
| robot.keyRelease(letter[i]); | |
| } | |
| } | |
| public static void main(String[] args) { | |
| TestRobot t = new TestRobot(); | |
| int[] executeNotepad = {KeyEvent.VK_WINDOWS,KeyEvent.VK_N,KeyEvent.VK_O,KeyEvent.VK_T,KeyEvent.VK_E,KeyEvent.VK_P,KeyEvent.VK_A,KeyEvent.VK_D,KeyEvent.VK_ENTER}; | |
| int[] maximizeIt = {KeyEvent.VK_ALT,KeyEvent.VK_SPACE,KeyEvent.VK_X}; | |
| int[] messageToPrint = {KeyEvent.VK_H,KeyEvent.VK_E,KeyEvent.VK_L,KeyEvent.VK_L,KeyEvent.VK_O}; | |
| t.execute(executeNotepad); | |
| t.execute(maximizeIt); | |
| t.execute(messageToPrint); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very cool!
I had to adjust a little to matter:
28 int[] maximizeIt = {KeyEvent.VK_ALT, KeyEvent.VK_SPACE, KeyEvent.VK_UP, KeyEvent.VK_UP, KeyEvent.VK_ENTER};