Search code examples
c#uwpxboxgamepad

Simulate gamepad input in UWP app on Xbox


I am trying to simulate user's input in UWP app running on Xbox. At first I tried to press a key via InjectedInputKeyboardInfo and it works fine.

var inputInjector = InputInjector.TryCreate();

InjectedInputKeyboardInfo inputKeyboardInfo = new InjectedInputKeyboardInfo
{
    KeyOptions = InjectedInputKeyOptions.ScanCode,
    ScanCode = 22
};

inputInjector.InjectKeyboardInput(new[] { inputKeyboardInfo });

Then I tried to press a key on gamepad and it actually does nothing. No error, no exception.

InjectedInputGamepadInfo info = new InjectedInputGamepadInfo
{
    Buttons = GamepadButtons.A
};

inputInjector.InjectGamepadInput(info);

I updated my package manifest:

  • added namespace xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
  • added IgnorableNamespaces="rescap"
  • added capability <rescap:Capability Name="inputInjectionBrokered" />

My app has min/target version 16299.
My Xbox runs on 16299.4055.


Solution

  • From OS build 17134 there is new API which can be used to simulate Xbox One controller, keyboard or mouse.

    https://learn.microsoft.com/en-us/windows/uwp/xbox-apps/uwp-remoteinput-api