Language \ Environment \ Comparison
 
Index
 
  The Processing 1.0 _ALPHA_ Reference is a work in progress.
If you see any errors or have any comments, please write to: reas at groupc.net
Name  

key

   
Examples  
// Click on the window to give it focus 
// and press the 'B' key 
 
void loop() { 
  if(keyPressed) { 
    if (key == 'b' || key == 'B') { 
      fill(0); 
    } 
  } else { 
    fill(255); 
  } 
  rect(25, 25, 50, 50); 
} 
// Click on the window to give it focus 
// and press the up and down arrow keys 
 
void loop() { 
  if(keyPressed) { 
    if (key == UP) { 
      fill(255); 
    } else if (key == DOWN) { 
      fill(0); 
    } 
  } else { 
    fill(126); 
  } 
  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 key variable is set to either UP, DOWN, LEFT, or RIGHT. Other special key constants are ALT, CONTROL, and SHIFT.
   
Syntax  
key
   
Usage   Web & Application
   
Related   keyPressed
keyCode
keyPressed()
keyReleased()
   
© 2004 - 2001 Massachusetts Institute of Technology and Interaction Design Institute Ivrea
Processing is an open project initiated by Ben Fry and Casey Reas