Skip to content

Instantly share code, notes, and snippets.

@martinth
Created July 14, 2011 14:01
Show Gist options
  • Save martinth/1082508 to your computer and use it in GitHub Desktop.
Save martinth/1082508 to your computer and use it in GitHub Desktop.
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.AWTException;
public class KeyPresser {
public static void main(String[] args) {
int delay = 0;
try {
delay = Integer.parseInt(args[0], 10);
Robot robot = new Robot();
while (true) {
robot.delay(delay*1000);
robot.keyPress(KeyEvent.VK_ENTER);
robot.delay(10);
robot.keyRelease(KeyEvent.VK_ENTER);
}
} catch (ArrayIndexOutOfBoundsException e) {
System.err.println("First parameter need to be a number");
System.exit(1);
} catch (NumberFormatException e) {
System.err.println("First parameter need to be a number");
System.exit(1);
} catch (Exception e) {
System.err.println("Unexpected error" + e.toString());
System.exit(1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment