key \ Language (API) \ Processing 1.0
Author: Casey Reas & Ben Fry
Description: Processing is an electronic sketchbook for developing ideas. It is a context for learning fundamentals of computer programming within the context of the electronic arts.
Keywords: Processing, Processing, Interactive Media, Electronic Arts, Programming, Java, Ben Fry, Casey Reas

Reference for Processing version 1.5. If you have a previous version, use the reference included with your software. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Javadoc.

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 recent key on the keyboard that was used (either pressed or released). For non-ASCII keys, use the keyCode variable. The keys included in the ASCII specification (BACKSPACE, TAB, ENTER, RETURN, ESC, and DELETE) do not require checking to see if they key is coded, and you should simply use the key variable instead of keyCode If you're making cross-platform projects, note that the ENTER key is commonly used on PCs and Unix and the RETURN key is used instead on Macintosh. Check for both ENTER and RETURN to make sure your program will work for all platforms.
Syntax |
    key
Usage | Web & Application
Related | keyPressed keyCode keyPressed() keyReleased()

Updated on August 30, 2010 04:29:39pm EDT