We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
keyboard test app (Read 651 times)
keyboard test app
Feb 12th, 2006, 12:01am
 
Rewrite of the example, includes a buffer to test # of simultaneous keypresses, and what regions of the keyboard are affected.
Code:

// Click on the image to give it focus,
// and then press any key

int value = 0;
int num_pressed=0;
String buf = "";

void draw() {
background(255,0,0);
fill(value);
for ( int i=0; i<num_pressed; i++ )
rect(25/num_pressed, 25/num_pressed, 50/num_pressed, 50/num_pressed);
println(buf);
}

void keyPressed()
{
if ( buf.indexOf(char(key))==-1 ) {
buf+=key;
value = 255;
num_pressed++;
}
}

void keyReleased()
{
String newbuf="";
while ( buf.indexOf(char(key)) != -1 ) {
for ( int i=0; i < buf.length(); i++ )
if ( buf.charAt(i)!=char(key) ) newbuf += buf.charAt(i);
buf=newbuf;
}
value = 0;
num_pressed--;
}
Page Index Toggle Pages: 1