/* Sendkeys * This is a Processing sketch that reads the keyboard * and sends keypresses out on the serial (as ascii). * * To have some sort of feedback to tell you the program is live * it displays a circle that turns white when you press a key and * fades to black if you leave it alone. * * CC-By Fredrik Bridell (bridell.com) 2007 */ import processing.serial.*; Serial serial; int baudRate = 9600; int t; // this stores the time since last key - used for feedback only void setup(){ // the graphics is for feedback only, not really important: size(100, 100); noStroke(); ellipseMode(CORNER); smooth(); t=0; // find and set up the serial port: String[] ports = Serial.list(); // a good guess on my windows PC is that the last port in the list // is the Arduino sitting on USB. serial = new Serial(this, ports[ports.length-1], baudRate); } void draw(){ // this is for visual feedback only - not for the serial stuff // fade the circle to black: fill(max(0, t--)); ellipse(0, 0, width, height); } // here's the real thing: just copy whatever you type to the serial port. void keyReleased(){ serial.write(key); t=255; // turn the feedback circle white }