Keyboard Interactions
Table of Contents
Why Are Keyboard Interactions Important?
The Key variable
Key Events
KeyPressed()
int value = 0;�� void draw() {� fill(value);� rect(25, 25, 50, 50);� }�� void keyPressed() {� if (value == 0) {� value = 255;}
else {� value = 0;}� }
Note: To get keyboard input to work click anywhere on the output window first so you “focus” on the window (let it know that you are typing to the window)
KeyReleased()
int value = 0;�� void draw() {� fill(value);� rect(25, 25, 50, 50);� }�� void keyReleased() {� if (value == 0) {� value = 255;}
else {� value = 0;}� }
Note: To get keyboard input to work click anywhere on the output window first so you “focus” on the window (let it know that you are typing to the window)
Summary
Keyboard Interaction Summary
Name | Use |
keyPressed() | Code inside this block is run one time when any key is pressed |
keyReleased() | Code inside this block is run one time when any key is released |
key | Stores the value of the most recently pressed key |
Examples and Practice Problems
Practice Problems!
One more thing...
MCPT is participating in the Inside Ride!