Skip to content

Conversation

@lea108
Copy link

@lea108 lea108 commented Nov 22, 2025

Breaking changes:
Event keys does change. The new axis names are based on GameInputGamepadState. The new button names are based on GameInputGamepadButtons

  • dwXpos -> leftThumbstickX
  • dwYpos -> leftThumbstickY
  • ...
  • button-0 => a
  • button-1 => b
  • ...

The range of analog axises has changed to [-1.0, 1.0].

Gampad id:s are different. It now uses GameInputDeviceInfo.deviceId.

Fixes:

Non-goal
For now as it appears that the different platforms use different names on buttons, axis etc. I have not tried to mimic a different platform in the gamepads library, but instead tries to keep it close to GameInput API, which does break against the current windows bindings.

Testing/feedback
Feel free to test this out. For me it works, but love if people test it out, break it and report issues or suggest fixes. :)

Pop this in your pubspec.yaml to use this PR:

dependency_overrides:
  gamepads_windows:
    git:
      url: https://github.com/lea108/gamepads.git
      ref: windows-api-rework
      path: packages/gamepads_windows

Breaking change: event keys does change as well as the value range
of axis input.

Fixes:
* Crash when gamepad is disconnected
* Possible stale thread on disconnect
* Sleep(4) in input loop to reduce CPU load
@lea108
Copy link
Author

lea108 commented Nov 22, 2025

Not sure if this is a "fix" or "feat" PR. but the motivation is to fix issues and make it more stable.

Which is yet to find out if this is/becomes more stable overall than the current windows bindings.

The new API is just the means I ended up following as it has potential to remove the read thread entirely if GameInput RegisterReadingCallback() actually would work.

@lea108 lea108 changed the title Update to Windows GameInput API feat: update to windows GameInput api Nov 22, 2025
@lea108
Copy link
Author

lea108 commented Nov 22, 2025

Since buttons now use named values like "a", "b", "menu" etc. I decided to drop the "button-" leading part of the key. I did take a look on other platforms and could not see that they use this prefix so decided to drop it for slightly shorter key values.

@spydon
Copy link
Member

spydon commented Nov 23, 2025

Not sure if this is a "fix" or "feat" PR. but the motivation is to fix issues and make it more stable.

Maybe a refactor:, but doesn't matter that much. :)

@spydon spydon changed the title feat: update to windows GameInput api refactor!: Update to windows GameInput api Nov 23, 2025
@zhuhaichao518
Copy link
Contributor

Great Work! I have been waiting for this for very long time. :)


std::cout << "Gamepad connected: " << gp->id << " : " << gp->name << std::endl;

std::thread read_thread(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still have a thread reading the gamepad state?Can we use RegisterReadingCallback to listen to the update of gamepad states?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an experiment branch on my github using that. I haven't wired it up back to Flutter, but it prints out to the log when those events are recevied.

However, it requires both developers and end-users to install an MSI that the NuGet package downloads which requires elevated user privileges in Windows.

I had a chat with @spydon in discord where we decided that due to that limitation, it was better to stay at GameInput v0 which this PR uses that does not require this MSI to be installed in order to receive gamepad data.

That said, if you have a game title that ship with an installer, at that point it probably is doable to include it. But then I think it is more and more common for even games to install to you user folder to skip the elevated user privileges dialog.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it wasn't for the requirement to install this .msi-file, I am all with you and I think using the callback would be better as GameInput itself has an input thread that calls the callback.

Now it is a question of priority - easy setup and easy distribution vs best possible performance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

@jonasbark
Copy link

Hi! I'm currently trying out your implementation and I'm struggling with

...\windows\flutter\ephemeral\.plugin_symlinks\gamepads_windows\windows\gamepad.h(11,10): error C1083: Datei (Include) kann nicht geöffnet werden: "GameInput.h": No such file or directory [...\build\windows\x64\plugins\gamepads_windows\gamepads_windows_plugin.vcxproj]

Is there anything special I need to install? I installed Microsoft GDK and fiddled a bit with the CMakeLists.txt of my project. I have limited experience with Windows dev

@lea108
Copy link
Author

lea108 commented Dec 3, 2025

Hi! I'm currently trying out your implementation and I'm struggling with

...\windows\flutter\ephemeral\.plugin_symlinks\gamepads_windows\windows\gamepad.h(11,10): error C1083: Datei (Include) kann nicht geöffnet werden: "GameInput.h": No such file or directory [...\build\windows\x64\plugins\gamepads_windows\gamepads_windows_plugin.vcxproj]

Is there anything special I need to install? I installed Microsoft GDK and fiddled a bit with the CMakeLists.txt of my project. I have limited experience with Windows dev

For me the file is located at this path:

C:\Program Files (x86)\Windows Kits\10\10.0.26100.0\um\GameInput.h

I believe that is Windows SDK which I think has been a requirement for Flutter on Windows, potentially via Visual Studio. But looking at the current installation instructions for Flutter with Windows, it looks like it is no longer a requirement. (I looked on the wrong Windows instructions, please see my next comment)

I am also a bit of a beginner in how to manage C++ dependencies in Windows, so potentially made a mistake here by assuming that Windows SDK can be taken for granted.

@lea108
Copy link
Author

lea108 commented Dec 3, 2025

I see now, the install instructions for Windows as a target, does still require installing Visual Studio and the Desktop Development C++ task.

I am still not sure if that installs Windows SDK or not for you.

It would be helpful to know if it is the case that it will make Windows SDK installed or not. Especially because if it doesn't, this PR likely has to use NuGet to get the header files.

@jonasbark
Copy link

jonasbark commented Dec 10, 2025

I set up a new Windows machine following the official instructions (Visual Studio + C++) and it worked without issues. My initial issue was also fixed by... a restart.

What I did notice is that the analog button values are reported in the opposite format to that on e.g. Android. For my test device (an 8bitdo mini) Windows reports button pressed as 1.0 and button released as 0.0. I have yet to confirm if it's the same case when not using your fork.

EDIT: also happens without your fork

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants