# Keyboard buttons

**URL:** <https://discourse.processing.org/t/keyboard-buttons/717>\
**Category:** Coding Questions\
**Created:** [June 5, 2018, 3:20am UTC](https://discourse.processing.org/t/keyboard-buttons/717 "2018-06-05T03:20:45Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [June 6, 2018, 11:45pm UTC](https://discourse.processing.org/t/keyboard-buttons/717/3 "2018-06-06T23:45:10Z")

</div>

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).

```auto
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.`

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

```

This can be used for simultaneous keypresses – or for a large collection of toggles:

```auto
void keyReleased(){
  if(flags.get(key)!=null){
    flags.put(key, !(flags.get(key)));
  } else {
    flags.put(key, Boolean.TRUE);
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/keyboard-buttons/717)._
