# How to register 2 keys at a time

**URL:** <https://discourse.processing.org/t/how-to-register-2-keys-at-a-time/4635>\
**Category:** Coding Questions\
**Created:** [October 19, 2018, 11:44am UTC](https://discourse.processing.org/t/how-to-register-2-keys-at-a-time/4635 "2018-10-19T11:44:57Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [October 23, 2018, 8:33pm UTC](https://discourse.processing.org/t/how-to-register-2-keys-at-a-time/4635/8 "2018-10-23T20:33:57Z")

</div>

Following up on @Sarah’s answer – I have shared a HashMap solution to this problem and ones like this a few times in the past. The HashMap approach is a bit nicer than int[1000] in that it can store any key you press, but ONLY stores the keys you press. Then instead of checking for keys, you do this:

```auto
void keyPressed(){
  flags.put(key, Boolean.TRUE);
}
void keyReleased(){
  flags.put(key, Boolean.FALSE);
}

```

Now you can check your map with get() and if it is true, the key is down.

Here is the code and explanation:

> [@Keyboard buttons](https://discourse.processing.org/t/keyboard-buttons/717/3):
>
> If you are doing more than a few keys, another general option is to use implement @TfGuy44’s boolean approach using a [HashMap](https://processing.org/reference/HashMap.html). import java.util.Map; HashMap\<Character,Boolean\> flags = new HashMap\<Character,Boolean\>(); Any key that gets pressed, put it in the map with a true… any key that gets released, take it out with a false. void keyPressed(){ flags.put(key, Boolean.TRUE); } void keyReleased(){ flags.put(key, Boolean.FALSE); } This can be used for simultaneous keypresses – or for a la…

---

_[View the full topic](https://discourse.processing.org/t/how-to-register-2-keys-at-a-time/4635)._
