Skip to content

Instantly share code, notes, and snippets.

@timpulver
Created September 24, 2012 13:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timpulver/3775852 to your computer and use it in GitHub Desktop.
Save timpulver/3775852 to your computer and use it in GitHub Desktop.
[Processing] Simulates a key press
import java.awt.AWTException;
import java.awt.Robot;
KeystrokeSimulator keySim;
void setup(){
keySim = new KeystrokeSimulator();
}
void draw(){
try{
keySim.simulate('C');
}
catch(AWTException e){
println(e);
}
}
import java.awt.Robot;
import java.awt.AWTException;
public class KeystrokeSimulator {
private Robot robot;
KeystrokeSimulator(){
try{
robot = new Robot();
}
catch(AWTException e){
println(e);
}
}
void simulate(char c) throws AWTException {
for (int i=0; i<10; i++) {
robot.delay(1000);
robot.keyPress(c);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment