# Simple multi-input tutorial for Processing beginners (ver 3.5.4)

**URL:** <https://discourse.processing.org/t/simple-multi-input-tutorial-for-processing-beginners-ver-3-5-4/26873>\
**Category:** Gallery\
**Created:** [January 8, 2021, 3:35am UTC](https://discourse.processing.org/t/simple-multi-input-tutorial-for-processing-beginners-ver-3-5-4/26873 "2021-01-08T03:35:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anon0908](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@Anon0908](https://discourse.processing.org/u/Anon0908)\
**Post date:** [January 8, 2021, 3:35am UTC](https://discourse.processing.org/t/simple-multi-input-tutorial-for-processing-beginners-ver-3-5-4/26873/1 "2021-01-08T03:35:10Z")

</div>

Many beginners and some intermediate coders have run into conflicting issues with using multiple key inputs for their sketches. keyCode and key are single-value variables that track the last key pressed. As such, they cannot store multiple sets of key data on their own.  
Thus, I provide the following template:

```auto
/*number-indexed keys:*/
boolean[] keys;
void setup() {
  /*I use 1 key but you can modify length to include up to all 128 byte values*/
  keys = new boolean[1];
  for (int i = 0; i < keys.length; i++) {
    keys[i] = false;
  }
}

void draw() {
  if (keys[0]) {
    //statements
  }
}

void keyPressed() {
  if (key == CODED) {
    /*keyCode 37 used for demonstration*/
    if (keyCode = 37) {
      keys[0] = true;
    }
  }
}

void keyReleased() {
  if (key == CODED) {
    /*keyCode 37 used for demonstration*/
    if (keyCode = 37) {
      keys[0] = false;
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 8, 2021, 12:33pm UTC](https://discourse.processing.org/t/simple-multi-input-tutorial-for-processing-beginners-ver-3-5-4/26873/2 "2021-01-08T12:33:33Z")

</div>

the way I usually do it is by creating a `char list[]` of acceptable inputs and a boolean list if the key is pressed and wire things like

```auto
if(pressed[0]) {
    //do stuff
}

```

---

<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:** [January 8, 2021, 2:33pm UTC](https://discourse.processing.org/t/simple-multi-input-tutorial-for-processing-beginners-ver-3-5-4/26873/3 "2021-01-08T14:33:45Z")

</div>

[Studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G](http://Studio.ProcessingTogether.com/sp/pad/export/ro.9cfU11egvzT6G)

https://www.openprocessing.org/sketch/718355/embed/
