function if space is pressed p5js code example
Example: 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;
}