Open SableRaf opened 1 year ago
I have posted a detailed description of the issue here hoping for answers:
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, andonKeyDown()
/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 theInputManager
class orregisterListener()
in theSensorManager
class, but I haven't found a method that would allow to register callbacks for button and joystick input in theInputDevice
class in the same way.
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.
Edit: An example of a Processing sketch running on an Anbernic 353V
References: