# Trap events with getHat in game control plus

**URL:** <https://discourse.processing.org/t/trap-events-with-gethat-in-game-control-plus/6138>\
**Category:** Libraries\
**Created:** [December 1, 2018, 10:43am UTC](https://discourse.processing.org/t/trap-events-with-gethat-in-game-control-plus/6138 "2018-12-01T10:43:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bryan/32/2538_2.png) [@bryan](https://discourse.processing.org/u/bryan)\
**Post date:** [December 1, 2018, 10:43am UTC](https://discourse.processing.org/t/trap-events-with-gethat-in-game-control-plus/6138/1 "2018-12-01T10:43:20Z")

</div>

Hi, i want to know if there’s a way to trap events with the dpad button in the game control plus library. i can trap events with buttons, for example the key A of the xbox controller might look like this: `xbox.getButton("a").plug(this, "my_function", ControlIO.ON_PRESS);`  
but i don’t know how to make it the dpad key works, i would expect something like this, in where i specify the key that i’m using, but no. `xbox.getHat("navigation").right().plug(this, "other_function", ControlIO.ON_PRESS);`

---

<div class="post-metadata">

**Author:** ![bryan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bryan/32/2538_2.png) [@bryan](https://discourse.processing.org/u/bryan)\
**Post date:** [December 3, 2018, 1:06am UTC](https://discourse.processing.org/t/trap-events-with-gethat-in-game-control-plus/6138/2 "2018-12-03T01:06:35Z")

</div>

@quark Hi, first of all thank you for this awesome library, and second sorry for tagging you but i still don’t know how to make this works. Greetings!

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [December 4, 2018, 9:30am UTC](https://discourse.processing.org/t/trap-events-with-gethat-in-game-control-plus/6138/3 "2018-12-04T09:30:46Z")

</div>

I have no problem with members tagging me, sometimes I end up missing a post about one of my libraries. 😄

OK, the ‘hat’ is the four position switch found on the top af a joystick handle. There is no hat on an xbox controller, at least not on mine.

---

<div class="post-metadata">

**Author:** ![bryan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bryan/32/2538_2.png) [@bryan](https://discourse.processing.org/u/bryan)\
**Post date:** [December 4, 2018, 11:02am UTC](https://discourse.processing.org/t/trap-events-with-gethat-in-game-control-plus/6138/4 "2018-12-04T11:02:47Z")

</div>

Thanks for reply!, and the only way that I can have access to the functionality of the directional pad button is calling it as a hat button. For example, I called that dpad “navigation” and this works for it `xbox.getHat("navigation").right().pressed()`

---

<div class="post-metadata">

**Author:** ![bryan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bryan/32/2538_2.png) [@bryan](https://discourse.processing.org/u/bryan)\
**Post date:** [December 4, 2018, 12:02pm UTC](https://discourse.processing.org/t/trap-events-with-gethat-in-game-control-plus/6138/5 "2018-12-04T12:02:28Z")

</div>

Or, how can i have access to the directions from the dpad and trap events? i tried using the getButton function, but it doesn’t works for this button, or probably i’m missing something.  
Greetings!

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [December 4, 2018, 2:07pm UTC](https://discourse.processing.org/t/trap-events-with-gethat-in-game-control-plus/6138/6 "2018-12-04T14:07:15Z")

</div>

Plug your controller into the USB port and run the configurator example sketch that comes with the library. In the window that opens select your controller. A new window opens and lists all the IO devices it finds and has indicators that light up when you operate the controller so you can see their names.

Also I suggest you look at the videos on my website.
