# Is there a way to detect 2 key presses at once?

**URL:** <https://discourse.processing.org/t/is-there-a-way-to-detect-2-key-presses-at-once/29100>\
**Category:** Coding Questions\
**Created:** [April 3, 2021, 10:03pm UTC](https://discourse.processing.org/t/is-there-a-way-to-detect-2-key-presses-at-once/29100 "2021-04-03T22:03:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![graph100](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/graph100/32/12557_2.png) [@graph100](https://discourse.processing.org/u/graph100)\
**Post date:** [April 3, 2021, 10:03pm UTC](https://discourse.processing.org/t/is-there-a-way-to-detect-2-key-presses-at-once/29100/1 "2021-04-03T22:03:13Z")

</div>

Hi, I’ve mainly been working in p5.js, and some time ago, I was porting one of my javascript games to processing and I noticed there isn’t really and equivalent in processing. I’ve tried:

```auto
if (keyPressed) {
  switch key {
    case "a":
      // do thing
      break;
    case "b":
      // do other thing
      break;
  }
}

```

but this doesn’t work if both are pressed and I’ve also tried with if statements. Is there an equivalent to this in processing? I want the key detection to work for every frame similar to the keyIsDown() function in p5js. Thanks!

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [April 3, 2021, 10:43pm UTC](https://discourse.processing.org/t/is-there-a-way-to-detect-2-key-presses-at-once/29100/2 "2021-04-03T22:43:30Z")

</div>

Hi @graph100,

You might want to look at those links (multiple keys is a known issue) :

- [Multiple Keyboard Input Example - OpenProcessing](https://openprocessing.org/sketch/100827/)

- [keycode - How Processing knows that user is pressing multiple key at the same time? - Stack Overflow](https://stackoverflow.com/questions/21376781/how-processing-knows-that-user-is-pressing-multiple-key-at-the-same-time)

- [Two keys pressed & three keys pressed simultaneously - Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/22644/two-keys-pressed-three-keys-pressed-simultaneously)

Also note that some keyboards don’t support the same number of keystrokes at a time :

> **[Rollover (key)](https://en.wikipedia.org/wiki/Rollover_(key))**
>
> Rollover is the ability of a computer keyboard to correctly handle several simultaneous keystrokes.
> During normal typing on a conventional computer keyboard, only one key is usually pressed at any given time, then released before the next key is pressed. However, this is not always the case. When using modifier keys such as Shift or Control, the user intentionally holds the modifier key(s) while pressing and releasing another key. Rapid typists may also sometimes inadvertently press a key before...

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 3, 2021, 11:14pm UTC](https://discourse.processing.org/t/is-there-a-way-to-detect-2-key-presses-at-once/29100/3 "2021-04-03T23:14:39Z")

</div>

> [@graph100](#):
>
> I want the key detection to work for every frame similar to the keyIsDown() function in p5js.

[https://www.reddit.com/r/processing/comments/bshqa8/how\_would\_i\_make\_a\_keypressed\_function\_support/eor5epo/](https://www.reddit.com/r/processing/comments/bshqa8/how_would_i_make_a_keypressed_function_support/eor5epo/)
