KeyPress Logic
Last updated
Was this helpful?
Last updated
Was this helpful?
The example project below shows several ways to use processing's key press events and boolean variables to add keyboard interaction to a program.
Example Khan Academy Project:
The example project below uses UP and DOWN arrows to change the value of variable: targetY, this is a global variable that's use to animate a rectangle by passing this value into the drawTarget function where it's used to control the y position of the rectangle.
Example:
The example code below uses the processing keyPressed event function. The code within the function is only executed when a key has been pressed, it's only executed once per key-press event. The example code below has logic that displays keys or sentences on the canvas based on the key that was pressed.