- The
keyPressed()
function is called once every time a key is pressed. Thekey
that was pressed is stored in the key variable. - The
keyReleased()
function is called once every time a key is released. Thekey
that was released will be stored in the key variable - The
keyTyped()
function is called once every time a key is pressed, but action keys such as Ctrl, Shift, and Alt are ignored. keyCode
stores the special key values (space, enter, up down etc) whenkey
isCODED
- Try the follwing one at a time.
void setup(){
size(500,375);
background(255);
smooth();
}
void draw(){
PFont font;
fill(0);
font = loadFont("CenturySchL-Roma-48.vlw");
textFont(font);
}
//case 1
void keyPressed() {
text("pressed ="+key, 15, 100);
}
//case 2
void keyReleased() {
text("released "+key, 15, 200);
}
//case 3
void keyTyped() {
println("released " + int(key) + " " + keyCode);
}