Created
February 17, 2016 23:14
-
-
Save Wieku/270308b17c3abc740740 to your computer and use it in GitHub Desktop.
osu! touch keyboard
This file contains 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
#include <CapacitiveSensor.h> | |
CapacitiveSensor sens1 = CapacitiveSensor(8,6); | |
CapacitiveSensor sens2 = CapacitiveSensor(4,2); | |
void setup() { | |
sens1.set_CS_AutocaL_Millis(0xFFFFFFFF); | |
sens2.set_CS_AutocaL_Millis(0xFFFFFFFF); | |
Serial.begin(115200); | |
} | |
bool clickz = false; | |
bool clickx = false; | |
void loop() { | |
long totalz = sens1.capacitiveSensor(20); | |
long totalx = sens2.capacitiveSensor(20); | |
if(totalz > 1000 && !clickz) { | |
Serial.println("zp"); | |
clickz = true; | |
} | |
if(totalx > 1000 && !clickx) { | |
Serial.println("xp"); | |
clickx = true; | |
} | |
if (totalz <= 1000 && clickz) { | |
clickz = false; | |
Serial.println("zr"); | |
} | |
if (totalx <= 1000 && clickx) { | |
clickx = false; | |
Serial.println("xr"); | |
} | |
} |
This file contains 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 processing.serial.*; | |
import java.awt.AWTException; | |
import java.awt.Robot; | |
import java.awt.event.KeyEvent; | |
Serial myPort; | |
Robot robot; | |
void setup() { | |
try { | |
robot = new Robot(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
exit(); | |
} | |
String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port | |
myPort = new Serial(this, portName, 115200); | |
} | |
void draw() { | |
if (myPort.available() > 0) { | |
String inBuffer = myPort.readStringUntil('\n'); | |
if (inBuffer != null) { | |
String val = new String(inBuffer).trim(); | |
if (val.equals("zp")) robot.keyPress(KeyEvent.VK_Z); | |
if (val.equals("xp")) robot.keyPress(KeyEvent.VK_X); | |
if (val.equals("zr")) robot.keyRelease(KeyEvent.VK_Z); | |
if (val.equals("xr")) robot.keyRelease(KeyEvent.VK_X); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment