 |
 |
 |
 |
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() |
|