Reference for Processing (BETA) version 0135+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Name

key

Examples
// Click on the window to give it focus
// and press the 'B' key

void draw() {
  if(keyPressed) {
    if (key == 'b' || key == 'B') {
      fill(0);
    }
  } else {
    fill(255);
  }
  rect(25, 25, 50, 50);
}
Description The system variable key always contains the value of the most recently pressed key on the keyboard. For detecting the arrow keys, the keyCode variable is set to either UP, DOWN, LEFT, or RIGHT.
Syntax
key
Parameters
Usage Web & Application
Related keyPressed
keyCode
keyPressed()
keyReleased()
Updated on December 20, 2005 02:03:00pm PST

Creative Commons License