Created
May 14, 2017 16:40
-
-
Save abhishekpratapa/0da21f64e6d821fe19b02d521cc98b05 to your computer and use it in GitHub Desktop.
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 spacebrew.*; | |
import java.awt.AWTException; | |
import java.awt.Robot; | |
import java.awt.event.KeyEvent; | |
Robot robot; | |
String server="192.168.0.32"; | |
String name="Emulator"; | |
String description ="Client that sends and receives boolean messages. Background turns yellow when message received."; | |
Spacebrew sb; | |
boolean debug = true; | |
boolean verbose = true; | |
void setup() { | |
sb = new Spacebrew( this ); | |
size(200, 200); | |
background(0); | |
noStroke(); | |
fill(102); | |
try { | |
robot = new Robot(); | |
} catch (AWTException e) { | |
e.printStackTrace(); | |
exit(); | |
} | |
sb.addSubscribe( "released_key", "release" ); | |
sb.addSubscribe( "pressed_key", "press" ); | |
sb.connect(server, name, description ); | |
} | |
void draw(){} | |
void onCustomMessage( String name, String type, String value ){ | |
println("got bool message " + name + " : " + type + ":" + value); | |
if(!debug){ | |
if(type.equals("press")){ | |
robot.delay(10); | |
robot.keyPress(int(value)); | |
robot.delay(10); | |
} | |
if(type.equals("release")){ | |
robot.delay(10); | |
robot.keyRelease(int(value)); | |
robot.delay(10); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment