# Tip: Do NOT addEventListener to draw()

**URL:** <https://discourse.processing.org/t/tip-do-not-addeventlistener-to-draw/8462>\
**Category:** Beginners\
**Created:** [February 16, 2019, 9:14pm UTC](https://discourse.processing.org/t/tip-do-not-addeventlistener-to-draw/8462 "2019-02-16T21:14:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![2000mater](https://avatars.discourse-cdn.com/v4/letter/2/ccd318/32.png) [@2000mater](https://discourse.processing.org/u/2000mater)\
**Post date:** [February 16, 2019, 9:14pm UTC](https://discourse.processing.org/t/tip-do-not-addeventlistener-to-draw/8462/1 "2019-02-16T21:14:27Z")

</div>

I don’t know if I have permission to leave tips but as a beginner I made the mistake of assuming an event listener works like keyIsDown(). As it turns out it doesn’t. I struggled so much with my framerate before finally figuring out this simple function adds a new listener to my project every frame. Next time I make sure it’s only run once.  
Btw, want to fullscreen your html script in a browser? Add this beauty to your **setup()**! This is that evil snippet 😑

```auto
document.addEventListener("keypress", function() {
    if (keyCode === 70) {
      document.documentElement.requestFullscreen();
    }
}, false);

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [February 17, 2019, 2:10am UTC](https://discourse.processing.org/t/tip-do-not-addeventlistener-to-draw/8462/2 "2019-02-17T02:10:50Z")

</div>

thank you very much for share and try to help!

-a- but i try your code ( in setup ) and get error

-b- where on my keyboard is “70”  
i recommend to document that kind of things in the code,  
and somehow tell the user what operation is possible  
( like with a print info to console… or canvas as intro screen )

-c- are you aware of the default function

```auto
function keyPressed() {}

```

see:  
[https://editor.p5js.org/kll/sketches/pg1U26vyW](https://editor.p5js.org/kll/sketches/pg1U26vyW)

fullscreen() does work in CHROME on OS: Raspbian and Win7  
but not in Firefox Win7

---

<div class="post-metadata">

**Author:** ![2000mater](https://avatars.discourse-cdn.com/v4/letter/2/ccd318/32.png) [@2000mater](https://discourse.processing.org/u/2000mater)\
**Post date:** [May 15, 2019, 9:31am UTC](https://discourse.processing.org/t/tip-do-not-addeventlistener-to-draw/8462/3 "2019-05-15T09:31:41Z")

</div>

hey!  
So I think I mainly used eventListener cuz fullscreen() did not seem to work on other sites when uploaded.  
And thanks for the tip of the ‘documenting’, I usually don’t leave comments, and that’s somewhat a bad habit of mine.  
Also I “commented” your /\* function \*/ and removed the comments at my original one and it seems the eventListener worked flawlessly. I don’t know what might be the issue when you try.
