Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add support for input from game controllers #715

Open
SableRaf opened this issue Dec 9, 2022 · 1 comment
Open

[Feature Request] Add support for input from game controllers #715

SableRaf opened this issue Dec 9, 2022 · 1 comment

Comments

@SableRaf
Copy link

SableRaf commented Dec 9, 2022

It would be great if Processing for Android could wrap the APIs for detecting and processing user input from game controllers that are already included in the Android framework. They are not currently easily accessible in Processing for Android. Making these APIs accessible in Processing would enable developers to create interactive experiences using game controllers on Android devices, including the increasingly popular Android-based gaming handhelds from the likes of Anbernic or Retroid but also any kind of Android smartphone or tablet with a bluetooth controller plugged in.

ezgif com-resize
Edit: An example of a Processing sketch running on an Anbernic 353V

References:

@SableRaf
Copy link
Author

SableRaf commented Dec 11, 2022

I have posted a detailed description of the issue here hoping for answers:

https://stackoverflow.com/questions/74763835/handle-inputs-from-a-gamepad-with-processing-for-android

Edit: here's the relevant part of the message:

I’m trying to use Processing for Android to get inputs from a physical game controller (with buttons and joysticks).

I am using the Android documentation on controller actions as a guide.

Tl;dr: I'm struggling to find how to override the necessary callbacks (onGenericMotionEvent(), onKeyDown(), onKeyUp()) in the context of Processing since it instantiates the Activity and View itself.

Here's what I have managed so far:

  • Compile Processing examples to the device (specifically the RG353V, an Android-based handheld gaming console from Anbernic)
  • Use android.view.InputDevice to make a list of input devices and output their names to the console
  • Filter the input devices that are game controllers
  • Register an input device listener to receive notifications about when input devices are added, removed or changed using inputManager.registerInputDeviceListener()
  • Get the main activity with Activity activity = getActivity()
  • Get the root view with ViewGroup rootView = activity.findViewById(android.R.id.content);
    I now want to capture button/joystick events but this is where my trouble starts.

All the examples I found involve implementing a custom view and overriding onGenericMotionEvent() for joystick events, and onKeyDown()/onKeyUp() for button events.

Only Processing instantiates the main Activity and View on its own, so I don't know to override those callbacks. Is it even possible to override a method on an instance of a class?

I was hoping to find something similar to registerInputDeviceListener() in the InputManager class or registerListener() in the SensorManager class, but I haven't found a method that would allow to register callbacks for button and joystick input in the InputDevice class in the same way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants