# Multiple Key Inputs

**URL:** <https://discourse.processing.org/t/multiple-key-inputs/9662>\
**Category:** Beginners\
**Created:** [March 26, 2019, 10:55pm UTC](https://discourse.processing.org/t/multiple-key-inputs/9662 "2019-03-26T22:55:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samira](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@Samira](https://discourse.processing.org/u/Samira)\
**Post date:** [March 26, 2019, 10:55pm UTC](https://discourse.processing.org/t/multiple-key-inputs/9662/1 "2019-03-26T22:55:17Z")

</div>

I’m trying to create a game where two people move at once. I’ve realised that you can’t have more than one key input at a time which makes my idea impossible. I was wondering if there was a way where I could have more than one key be pressed at once. Thank you.

---

<div class="post-metadata">

**Author:** ![bmoren](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bmoren/32/68_2.png) [@bmoren](https://discourse.processing.org/u/bmoren)\
**Post date:** [March 26, 2019, 11:36pm UTC](https://discourse.processing.org/t/multiple-key-inputs/9662/2 "2019-03-26T23:36:54Z")

</div>

Hi Samira,

check out the keyIsDown function:  
[https://p5js.org/reference/#/p5/keyIsDown](https://p5js.org/reference/#/p5/keyIsDown)

I’ll get an example going here for you too!

---

<div class="post-metadata">

**Author:** ![bmoren](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bmoren/32/68_2.png) [@bmoren](https://discourse.processing.org/u/bmoren)\
**Post date:** [March 26, 2019, 11:43pm UTC](https://discourse.processing.org/t/multiple-key-inputs/9662/3 "2019-03-26T23:43:58Z")

</div>

if you check the keyIsDown() during draw and use an if statement you can check for what keys are down and detect multiple keys.

one thing of note, in the online editor, you might have to ‘click’ on the canvas to make that ‘pane’ active before the key events will be recognized

```auto
let p1x = 0
let p2x = 0

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
  
  
  //65 is the A key
  if(keyIsDown(65) == true ){
    
    p1x += 1
  }
  
  //76 is the L key
  if(keyIsDown(76) == true ){
    p2x += 1
  }
  
  
  //put the ellipses on the screen
  ellipse(p1x,height/4,10,10)
  ellipse(p2x,height/4*3,10,10)

  
}

```

---

<div class="post-metadata">

**Author:** ![Samira](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@Samira](https://discourse.processing.org/u/Samira)\
**Post date:** [March 27, 2019, 12:10am UTC](https://discourse.processing.org/t/multiple-key-inputs/9662/4 "2019-03-27T00:10:22Z")

</div>

Oh my god you are a lifesaver, thank you so much. I didn’t even know this function existed!
