# Capturing game controller button events in Processing for Android

**URL:** <https://discourse.processing.org/t/capturing-game-controller-button-events-in-processing-for-android/40073>\
**Category:** Processing for Android\
**Created:** [December 8, 2022, 6:41pm UTC](https://discourse.processing.org/t/capturing-game-controller-button-events-in-processing-for-android/40073 "2022-12-08T18:41:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [December 8, 2022, 11:17pm UTC](https://discourse.processing.org/t/capturing-game-controller-button-events-in-processing-for-android/40073/2 "2022-12-08T23:17:19Z")

</div>

> [@sableraph](#):
>
> … as these concepts don’t really fit with my understanding of Processing.

Disclaimer: I’ve never dealt w/ Android coding. This is purely blind advice! 🕶

- In Java everything must be inside a class or interface.
- Processing hides that basic truth from us when our code is inside a “.pde” file.
- But if we check the “.java” file which got transpiled out of our “.pde” files we’ll realize everything ends up wrapped inside a PApplet subclass after all.
- When we need to define a callback function in Java, that also ends up belonging to some class or interface.
- So even callbacks gotta belong to some datatype and all of its inherited datatypes.
- And consequently we need to pass an instance of a callback’s class instead of the callback itself.
- Unless a callback belongs to a [@FunctionalInterface](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/FunctionalInterface.html); in which case we can alternatively pass a lambda expression instead.
- According to Android’s documentation, we’re advised to create a helper class w/ suggested name Dpad.
- Plus a subclass which [`extends`](https://processing.org/reference/extends.html) class View w/ suggested name GameView, in which we can [@Override](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Override.html) View’s callback functions.
- Basically that’s where you should define your customized **onKeyDown()** callback event method aKa listener.

> [@sableraph](#):
>
> How can I capture these gamepad events in Processing for Android?

- Unfortunately that’s where I can’t help you anymore! 😢
- It seems like parent class View is merely a placeholder for listener callback methods.
- Instantiating a `new` View doesn’t magically activate its listeners at all.
- You’d still need to pass its instance to some “unknown” Android method which will then register & start listening to the View’s callbacks within your sketch app.

---

_[View the full topic](https://discourse.processing.org/t/capturing-game-controller-button-events-in-processing-for-android/40073)._
