# How to trigger keypress events in p5.js

**URL:** <https://discourse.processing.org/t/how-to-trigger-keypress-events-in-p5-js/24082>\
**Category:** Coding Questions\
**Created:** [September 23, 2020, 1:47pm UTC](https://discourse.processing.org/t/how-to-trigger-keypress-events-in-p5-js/24082 "2020-09-23T13:47:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yashkhasgiwala](https://avatars.discourse-cdn.com/v4/letter/y/df705f/32.png) [@yashkhasgiwala](https://discourse.processing.org/u/yashkhasgiwala)\
**Post date:** [September 23, 2020, 1:47pm UTC](https://discourse.processing.org/t/how-to-trigger-keypress-events-in-p5-js/24082/1 "2020-09-23T13:47:59Z")

</div>

I want my code to press keyboard keys if a certain condition is True in p5.js library. For example:

```auto
a = true

if (a) {
  // Press UP Key
} else {
  // Press DOWN Key
}

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [September 24, 2020, 12:02am UTC](https://discourse.processing.org/t/how-to-trigger-keypress-events-in-p5-js/24082/2 "2020-09-24T00:02:52Z")

</div>

Hi @yashkhasgiwala  
I don’t know how you will use it, but I found [this](https://gist.github.com/ejoubaud/7d7c57cda1c10a4fae8c). At least this code doesn’t give any error.
