Function keyPressed() doesn't run in my Web Editor

Hi i don’t know why this code runs well in the p5js reference but not in my web editor could you help me please?

let value = 0;
function draw() {
fill(value);
rect(25, 25, 50, 50);
describe(black rect center. turns white when left arrow pressed and black when right.);
}
function keyPressed() {
if (keyCode === LEFT_ARROW) {
value = 255;
} else if (keyCode === RIGHT_ARROW) {
value = 0;
}
}

1 Like

Code looks okay

Sometimes the window doesn’t have the focus so you have to click on it first

1 Like

Thanks so much that’s good now :smile:

1 Like