Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using DirectInput with XBOX One controller and window focus on Windows 10

I am trying to use DirectInput to capture XBOX One controller input signals. I am tying it to a C# WinForms application. The issue I am having is: When the form has focus, it captures inputs just fine. When the window loses focus, I don't get any feedback. On Windows 7, this isn't an issue.

I have tried other controllers on Windows 10: PS4, Logitech, Steering Wheels, etc... Everything works as expected: When the window loses focus, I still get feedback. It's just the XBOX One controller on Windows 10.

I thought maybe it had something to do with this line:

dev.SetCooperativeLevel(_ctlParent, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);

But, even if I take that line out, everything still acts the same.

It seems like the XBOX One controller ignores the CooperativeLevel.Background flag and adds the CooperativeLevel.Foreground flag. Here is some more info about the flags.

Is there anyone else familiar with this issue that has figured out a work around?

like image 248
Andy Avatar asked Oct 20 '25 13:10

Andy


2 Answers

Been exploring this myself regarding XBox One controllers. Each API has its own set of limitations when it comes to XBox One and XBox360 controllers.

Here's a summary of what I've learned:

Windows.Gaming.Input ref

Unlimited(?) number of controllers on Windows 10.
(Until recently I thought the limit was 8 but I've tested with 9 XBox 360/XBox One controllers so the MAX_PLAYER_NUMBER=8 found in DirectXTK is not set according to a real limit for Windows 10. ref)

Limitations:

  • Controllers can’t be accessed in the background...
    (Not 100% sure though. I haven't gotten the controllers to work in the background myself and documentation says this limitation exists for UWP apps. ref )
  • Only works on UWP devices (e.g. Windows 10, XBoxOne, Windows Tablets, etc)
  • The Gamepad class only supports Xbox One certified or Xbox 360 compatible gamepads (ref), other gamepads can be accessed via the RawGameController class (ref).

XInput ref

API for accessing 4 XInput compatible controllers (e.g. XBox 360 or XBox One controllers)

  • XInput controllers can be accessed in the background.

Limitations:

  • Max 4 controllers.
  • Only XInput capable devices.
  • Unable to activate the extra 2 rumble motors in XBox One controller triggers. (Use Windows.Gaming.Input to do that.)

DirectInput ref

The oldest of these APIs.
Unlimited number of controllers (?)

Limitations:

  • XBox One controllers cannot be accessed in the background. (Bug or a feature?)
  • XBox 360 and XBox One controllers have triggers on the same axis, no guide button and no rumble.
  • Windows Store Apps can’t use DirectInput. ref
  • Microsoft no longer recommends using DirectInput. ref

Raw Input ref

Unlimited number of controllers (Lacking reference. Tested with 9 controllers.)

  • XBox One and other controllers can be accessed in the background.
    (Use this source code to try it out: ref)

Limitations:

  • XBox 360 and XBox One controllers have triggers on the same axis, no guide button and probably no rumble. (Tested using this source code ref)
like image 188
supersmo Avatar answered Oct 23 '25 07:10

supersmo


The drivers for the Xbox 360 Common Controller and the Xbox One Controller both emulate "HID" for use with the legacy DirectInput API for older games, but the emulation tends to have some quirks like this one.

Probably the best solution is to use XINPUT for these controllers and only fall back to DirectInput for legacy HID controllers. For Windows 10 DirectX 12 / UWP apps you can use Windows.Gaming.Input directly as well.

See XINPUT and Windows 8 and DirectX Tool Kit: Now with GamePads.

like image 45
Chuck Walbourn Avatar answered Oct 23 '25 06:10

Chuck Walbourn