Avalonia
Avalonia copied to clipboard
Gamepad/controller input support
Is your feature request related to a problem? Please describe. Controller (xbox controller or remote control) should be treated as valid user input that should be mapped into XY focus navigation. So users can use Avalonia applications using only their controllers.
Additional context UWP APIs: High level integration of controller with app navigation (similarly how it's done with keyboard input): https://docs.microsoft.com/en-us/windows/apps/design/input/gamepad-and-remote-interactions Lower level Gamepad API: https://docs.microsoft.com/en-us/uwp/api/windows.gaming.input.gamepad?view=winrt-22000
I guess it's very low priority requests, but still would be nice to have somewhere in the future. Majority of UI frameworks don't treat controllers as they should and from my knowledge it works only with UWP apps.
The problem with gamepads is the key mapping. What button is X again?
@kekekeks at least xbox contoller style mapping is expected. Also on windows we don't have native ps4-5 controller support anyway - it is always mapped to xbox buttons. Would like to know if it's different on macOS/Linux.
And in the end it might be an issue only if we want to have full support for gamepad input (just like MonoGame has for example). Though I just checked, they decided also to support only Xbox style buttons - https://github.com/MonoGame/MonoGame/blob/develop/MonoGame.Framework/Input/GamePadButtons.cs (which might be legacy of XNA).
And for XY focus navigation it should be clear on Windows. And for other platforms/input methods we might want to have customizable mapping service, just like we have for platform-depended hotkeys.
Xbox/remote mapping to keyboard, quite simple, but sufficient:
Keyboard | Gamepad/remote |
---|---|
Arrow keys | D-pad (also left stick on gamepad) |
Spacebar | A/Select button |
Enter | A/Select button |
Escape | B/Back button |
It seems HTML JS standard just gave up about xbox-vs-ps mapping and used index based standardization. https://developer.mozilla.org/en-US/docs/Web/API/Gamepad/mapping
And that actually makes more sense.
I think we should stick to the HTML JS standard since it covers more platforms and even has some VR/AR controllers for future-proofing.
Also on windows we don't have native ps4-5 controller support anyway
Ah, yes, I remember the horrors of reflashing and effectively disabling your entire bluetooth adapter so it could work with dualshock. Use Windows, they said, gaming works out of the box, they said.
On Linux and macOS those are supported natively by the built-in Bluetooth stack.
I would like to put my hand up for work on implementing some sort of gamepad interface.
@kekekeks at least xbox contoller style mapping is expected. Also on windows we don't have native ps4-5 controller support anyway - it is always mapped to xbox buttons. Would like to know if it's different on macOS/Linux.
And in the end it might be an issue only if we want to have full support for gamepad input (just like MonoGame has for example). Though I just checked, they decided also to support only Xbox style buttons - https://github.com/MonoGame/MonoGame/blob/develop/MonoGame.Framework/Input/GamePadButtons.cs (which might be legacy of XNA).
And for XY focus navigation it should be clear on Windows. And for other platforms/input methods we might want to have customizable mapping service, just like we have for platform-depended hotkeys.
Xbox/remote mapping to keyboard, quite simple, but sufficient:
Keyboard Gamepad/remote Arrow keys D-pad (also left stick on gamepad) Spacebar A/Select button Enter A/Select button Escape B/Back button
Thinking about this, gamepads are typically polled rather than receiving events like one would with WM_* messages. Do we want these controllers always mapping to keyboard inputs? What if an app developer wants to talk to the controller specifically and not have these inputs translated into keyboard events?
I don't want to be super-formal about it, but if you're able to craft up some specifications for what the interface should look like (I can get started making something like the web-API linked above).
I would also ask how should the app developer ask for the controllers/gamepads, did we want to provide a static reference to getting the controllers like with the web API?
AvaloniaGamepadProvider.GetGamepads()
returning an array of Gamepad objects matching the web API?
I could definitely get an implementation working in Windows, maybe Linux/Unix (Don't know if libudev
works under MacOSX), but would not know how to do that on Android, iOS, and the Web JS/WASM.
Do note that the GDK GameInput API isn't always available on Windows 10, it was included in a newer build and may not be present in older builds. It was not available in Windows 10 IoT 2019 LTSC, it is in Windows 10 IoT 2021 LTSC.