0

I am trying to create an UWP app that uses xinput. Trying to get input from a controller using a WPF app , all good. Trying the same code in a UWP app nothing. Am I doing something wrong or xinput really doesn't work with UWP.

Mihail Georgescu
  • 405
  • 3
  • 14

1 Answers1

2

There is a new WinRT API in the Windows.Gaming.Input namespace for universal Windows apps. This API supports both the Xbox 360 Common Controller and the Xbox One controller, including access to the left/right trigger motors. The latest version of GamePad is implemented using this new API when built for Windows 10. You can refer to MSDN for Windows.Gaming.Input namespace.

As about XInput: For UWP, you can continue to use the XInput 1.4 API but need to change from linking to xinput.lib to xinputuap.lib, which is an adapter for the new API for universal Windows apps--this adapter does not exist headset audio either. This blog may help you.

Fangfang Wu - MSFT
  • 1,062
  • 6
  • 7
  • Ohh interesting about the new lib . Thank you. I'll give it a try. – Mihail Georgescu Oct 21 '15 at 10:45
  • In C# you usually import unmanaged code using the [DllImport] attrbute. So for this I had to [DllImport("XInput1_4.dll")] , any idea how can I achive what you suggested? I searched around the web but nothing. Sorry but I am not an expert , still trying to learn stuff. Thank you for your help Fangfang Wu, – Mihail Georgescu Oct 21 '15 at 13:39
  • 1
    There is a "xinputuwp.lib" under system's "windows kits" folder. Use this lib file: 1.In the project properties for the UWP project, in the Linker section, add Xinputuwp.lib to the library in the Input property; 2. in your project, include "xinputuwp.h". Then it is OK to go. Or you can just use "Windowsapp.lib" which encompasses all UWP APIs. – Fangfang Wu - MSFT Oct 22 '15 at 01:25
  • Again! Thank you FangFang for your time ! The problem is that works in C++ projects but not in C# . – Mihail Georgescu Oct 22 '15 at 09:18
  • 1
    SharpDX has a C# wrappers for Xinput. You can find it here: http://sharpdx.org/documentation/api – Fangfang Wu - MSFT Oct 22 '15 at 14:00
  • Just checked it , sadly SharpDx.XInput package not compatible with UWP , I'll keep digging , yea a good wrapper could do it, too bad I don't know C++. Time to learn C++ :) – Mihail Georgescu Oct 22 '15 at 14:25
  • 1
    You can create a winRT component which can be consumed by UWP application. Then in the winRT compoment, add reference to XINPUTUWP.dll. You can find something help here: http://blogs.msdn.com/b/chrisbarker/archive/2014/10/08/consuming-a-c-library-project-from-a-windows-phone-store-app.aspx – Fangfang Wu - MSFT Oct 22 '15 at 15:00