Skip to content

Instantly share code, notes, and snippets.

@abhishekpratapa
Created May 14, 2017 16:40
Show Gist options
  • Save abhishekpratapa/0da21f64e6d821fe19b02d521cc98b05 to your computer and use it in GitHub Desktop.
Save abhishekpratapa/0da21f64e6d821fe19b02d521cc98b05 to your computer and use it in GitHub Desktop.
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