Created
September 24, 2012 13:05
-
-
Save timpulver/3775852 to your computer and use it in GitHub Desktop.
[Processing] Simulates a key press
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; | |
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