p5 key pressed enter code example
Example 1: how to register key presses in p5.js
function keyPressed() {
if (keyCode === LEFT_ARROW) {
value = 255;
}
Example 2: p5js check for keyboard keys
let value = 0;
function draw() {
fill(value);
rect(25, 25, 50, 50);
}
function keyTyped() {
if (key === 'a') {
value = 255;
} else if (key === 'b') {
value = 0;
}
// uncomment to prevent any default behavior
// return false;
}