为Xbox之一的Windows UWP控制器支持 [英] Controller support for Xbox one in Windows UWP

查看:221
本文介绍了为Xbox之一的Windows UWP控制器支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我应该如何办理UWP应用定位的Xbox一个输入。我注意到DirectInput的,但我看到它的两个问题我用例:


  1. MSDN ,似乎只支持Xbox 360的控制器


      

    XINPUT是一个API,允许应用程序从Xbox 360控制器的Windows的输入。控制器的隆隆声效果和语音输入和输出的支持。



  2. DirectX和其所有的API的(的Direct2D,Direct3D的,XINPUT等)仅支持C / C ++。这意味着即使XINPUT支持Xbox One上的控制器,I不能使用C#或JavaScript来开发真正普及应用。


哪些选项我有(至少就为C#而言)用于在Windows UWP的应用支持的Xbox一个控制器支持?

更新

由于一对夫妇指着正确的命名空间有用的答案,我想我已经合成使用一些code Windows.Gaming.Input

  / *
 *注:我没有测试此code。
 *如果不正确,请不要编辑与修复。
 * /
使用Windows.Gaming.Input;//唧唧歪歪无聊的东西...//获取第一个控制器
VAR控制器= Gamepad.Gamepads.First();//获取当前状态
VAR读数= controller.GetCurrentReading();//检查是否左边的导火索是德pressed一半左右一路下滑
如果(reading.LeftTrigger == 0.5)
{
    //做任何
}

如果您使用的是JavaScript的话:

  VAR控制器= Windows.Gaming.Input.Gamepad.gamepads.first();
VAR读数= controller.getCurrentReading();如果(reading.leftTrigger === 0.5){
    //做任何
}


解决方案

看看的<一个href=\"https://msdn.microsoft.com/en-us/library/windows/apps/windows.gaming.input.aspx\">Windows.Gaming.Input命名空间。它的<一个href=\"https://msdn.microsoft.com/en-us/library/windows/apps/windows.gaming.input.gamepad.aspx\">GamePad类是在所有器件系列和语言的通用API合同,并可用。

I am wondering how I am supposed to handle input for UWP apps targeting Xbox One. I have noticed DirectInput, but I see two issues with it for my use cases:

  1. From MSDN, it only seems to support Xbox 360 controllers

    XInput is an API that allows applications to receive input from the Xbox 360 Controller for Windows. Controller rumble effects and voice input and output are supported.

  2. DirectX and all of its API's (Direct2d, Direct3D, Xinput, etc...) are only supported on C / C++. That means even if Xinput supported Xbox one controllers, I could not use C# or JavaScript to develop truly universal apps.

What options do I have (at least as far as C# is concerned) for supporting Xbox One controller support on a Windows UWP app?

UPDATE

Due to a couple of helpful answers pointing the right namespace, I think I have synthesized some code using Windows.Gaming.Input

/*
 * Note: I have not tested this code.
 * If it is incorrect, please do edit with the fix.
 */
using Windows.Gaming.Input;

// bla bla bla boring stuff...

// Get the first controller
var controller = Gamepad.Gamepads.First();

// Get the current state
var reading = controller.GetCurrentReading();

// Check to see if the left trigger was depressed about half way down
if (reading.LeftTrigger == 0.5;)
{
    // Do whatever
}

If you are using JavaScript then:

var controller = Windows.Gaming.Input.Gamepad.gamepads.first();
var reading = controller.getCurrentReading();

if (reading.leftTrigger === 0.5) {
    // Do whatever
}

解决方案

Take a look at the Windows.Gaming.Input namespace. Its GamePad class is in the Universal API contract and available on all device families and languages.

这篇关于为Xbox之一的Windows UWP控制器支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆