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

Question: Gamepad support in WinUI 3 #6891

Closed
camhw opened this issue Mar 28, 2022 · 9 comments
Closed

Question: Gamepad support in WinUI 3 #6891

camhw opened this issue Mar 28, 2022 · 9 comments
Labels

Comments

@camhw
Copy link

camhw commented Mar 28, 2022

Is there any info on gamepad support in Windows App SDK for WinUI 3? Is it possible that it'd make it into WinAppSDK 1.1 or 1.2? I haven't seen mention of it in the WinAppSDK roadmap, WinUI 3 roadmap, or in any of the community calls.

The latest info I could find was that it isn't supported in WinUI 3 GA.

Edit: Clarified the question here.

@camhw camhw added the question label Mar 28, 2022
@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Mar 28, 2022
@ojhad ojhad added product-winui3 WinUI 3 issues and removed needs-triage Issue needs to be triaged by the area owners labels Mar 28, 2022
@ojhad
Copy link
Contributor

ojhad commented Mar 28, 2022

@codendone Is there any info on this question?

@castorix
Copy link

Gamepads work with WinUI
I tested with an old gamepad which is not recognized by XInput, but then I tested with DirectInput and it worked
(I added a WM_TIMER message to check button status with IDirectInputDevice8::GetDeviceState, like in MS samples)

@camhw
Copy link
Author

camhw commented Apr 4, 2022

@castorix Thanks for the response 👍

I should have been clearer in my original question, sorry about that. UWP has out of the box support to navigate and interact with the UI with gamepads, whereas WinUI3 in WinAppSDK doesn't seem to have this yet (or at least I wasn't able to get it working). I'm wondering if anyone has any insight into the current state of this, or if there are any plans for it if this is indeed the case. This is the sort of support I'm looking for: https://docs.microsoft.com/en-us/windows/apps/design/input/gamepad-and-remote-interactions.

I did end up testing Windows.Gaming.Input, and this seems to work entirely as expected. So as an alternative I'd imagine I can either map gamepad inputs to keyboard inputs, or use FocusManager to emulate the above support.

I'll keep this issue updated as I find time to continue investigating, though insight from anyone who's had experience with this would certainly be appreciated.

@camhw
Copy link
Author

camhw commented Apr 27, 2022

For now, what I've done is use InputInjector to map gamepad inputs to keyboard inputs, and enable navigation using keyboard navigation strategies (e.g. XYFocusKeyboardNavigation). As far as I can tell, this is the simplest way of achieving UWP's out of the box gamepad navigation without implementing custom focus management logic. This should also support focus navigation strategies.

From the sounds of it, UWP does the reverse and maps keyboard input to gamepad inputs 🤔 So if anyone knows of a more direct way to do this, I'd love to hear it.

@camhw
Copy link
Author

camhw commented Apr 27, 2022

From the sounds of it, UWP does the reverse and maps keyboard input to gamepad inputs

The moment I posted this I realized it's likely that the more direct way that I'm looking for would be to just inject gamepad inputs, if WinAppSDK is also doing this mapping. InjectGamepadInput didn't work out, this is just treated as another controller.

As it turns out, Window.System.VirtualKey also has gamepad inputs as virtual keys. Injecting these as keyboard input results in the exact out of the box UI navigation that UWP has, even with XYFocusKeyboardNavigation disabled.

I'm happy to move forward with this solution for now, unless anyone has any suggestions. I'll close the issue in a few days otherwise.

@seanocali
Copy link

seanocali commented May 1, 2022

So just so I'm clear this 10 month old article is total BS, right? None of this actually works, nor has it ever worked in WinUI 3.
https://docs.microsoft.com/en-us/windows/apps/design/input/gamepad-and-remote-interactions

I have an Xbox One controller and there's no gamepad support whatsoever. KeyDown/KeyUp doesn't register events for VirtualKey.Gamepad*, no XYNavigation, no FocusEngage, no Mouse Mode, nothing. All of these except Mouse Mode works in a UWP project using the same hardware.

@seanocali
Copy link

From the sounds of it, UWP does the reverse and maps keyboard input to gamepad inputs

The moment I posted this I realized it's likely that the more direct way that I'm looking for would be to just inject gamepad inputs, if WinAppSDK is also doing this mapping. InjectGamepadInput didn't work out, this is just treated as another controller.

As it turns out, Window.System.VirtualKey also has gamepad inputs as virtual keys. Injecting these as keyboard input results in the exact out of the box UI navigation that UWP has, even with XYFocusKeyboardNavigation disabled.

I'm happy to move forward with this solution for now, unless anyone has any suggestions. I'll close the issue in a few days otherwise.

So you're saying that a Control's XYNavigation and FocusEngage responds to keyboard injection of a gamepad VirtualKeys? How do you trigger the injection with an actual gamepad though? Using Win32 API?

@camhw
Copy link
Author

camhw commented May 2, 2022

So just so I'm clear this 10 month old article is total BS, right? None of this actually works, nor has it ever worked in WinUI 3.
https://docs.microsoft.com/en-us/windows/apps/design/input/gamepad-and-remote-interactions

It worked with WinUI3 in UWP (before the switch to WinAppSDK). I think this article is still valuable despite it not functioning in WinUI3 in WinAppSDK by default, since it shows the keyboard to gamepad mappings and gets across the general philosophy well.

So you're saying that a Control's XYNavigation and FocusEngage responds to keyboard injection of a gamepad VirtualKeys?

Yep, seems that way 👍

How do you trigger the injection with an actual gamepad though?

I'm personally using Windows.Gaming.Input to map gamepad state to keyboard inputs via InputInjector.InjectKeyboardInput. One thing to note about this library is Gamepad.Gamepads() will be empty on app launch (this is the case for UWP as well). You need to listen to the Gamepad.GamepadAdded event instead.

@camhw
Copy link
Author

camhw commented May 3, 2022

Going to close this issue since a workaround has been identified.

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

No branches or pull requests

4 participants