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

**URL:** <https://discourse.processing.org/t/function-keypressed-doesnt-run-in-my-web-editor/43053>\
**Category:** p5.js\
**Created:** [October 25, 2023, 11:27am UTC](https://discourse.processing.org/t/function-keypressed-doesnt-run-in-my-web-editor/43053 "2023-10-25T11:27:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olibri](https://avatars.discourse-cdn.com/v4/letter/o/eb9ed0/32.png) [@Olibri](https://discourse.processing.org/u/Olibri)\
**Post date:** [October 25, 2023, 11:27am UTC](https://discourse.processing.org/t/function-keypressed-doesnt-run-in-my-web-editor/43053/1 "2023-10-25T11:27:29Z")

</div>

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;  
}  
}

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 25, 2023, 1:57pm UTC](https://discourse.processing.org/t/function-keypressed-doesnt-run-in-my-web-editor/43053/2 "2023-10-25T13:57:17Z")

</div>

Code looks okay

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

---

<div class="post-metadata">

**Author:** ![Olibri](https://avatars.discourse-cdn.com/v4/letter/o/eb9ed0/32.png) [@Olibri](https://discourse.processing.org/u/Olibri)\
**Post date:** [October 25, 2023, 2:13pm UTC](https://discourse.processing.org/t/function-keypressed-doesnt-run-in-my-web-editor/43053/3 "2023-10-25T14:13:10Z")

</div>

Thanks so much that’s good now 😄
