Xbox One 控制器输入到 UWP 应用程序 [英] Xbox One Controller input to UWP App

查看:30
本文介绍了Xbox One 控制器输入到 UWP 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使 Xbox One 控制器与 UWP 应用程序交互,并研究了 Gamepad 类(基于评论中提到的建议 - Windows UWP 中对 Xbox one 的控制器支持).我有两个问题:

I have been trying to make an Xbox One controller interact with a UWP application and have looked into the Gamepad class (based on the suggestions mentioned in the comments - Controller support for Xbox one in Windows UWP). I have 2 issues:

1) Gamepad.Gamepads.Count 为我返回 0,即使我的 Xbox One 控制器在应用程序在 Xbox 上运行时打开.

1) Gamepad.Gamepads.Count returns 0 for me even when I have my Xbox One controller switched on while the application is running on Xbox.

2) 我不知道,我如何准确地评估按下 A、B、X 和 Y 按钮的时间并访问左右拇指杆的坐标.

2) I do not know, how exactly can I assess when the A, B, X and Y buttons are pressed and also access the coordinates of the Left and Right Thumbsticks.

关于上述 2 点的任何指导,都会对我非常有帮助.谢谢!

Any guidance about the 2 points mentioned above, would be very helpful for me. Thanks!

推荐答案

通过控制器处理输入的一种方法是仅使用 keypress 事件.

One way to handle input, via the controller, is by just using keypress events.

document.addEventListener('keypress', function(e){
    switch (e.keyCode) {
        case 211:  // GamepadLeftThumbstickUp
        case 203:  // GamepadDPadUp
            break;

        case 212:  // GamepadLeftThumbstickDown
        case 204:  // GamepadDPadDown
            break;

        case 214:  // GamepadLeftThumbstickLeft
        case 205:  // GamepadDPadLeft
            break;

        case 213:  // GamepadLeftThumbstickRight
        case 206:  // GamepadDPadRight
            break;

        case 195:  // A Button
            break;

        case 196: // B button
            break;

        case 197: // X Button
            break;

        case 198: // Y Button
            break;

        case 208: // View button
            break;

        case 207: // Menu button
            break;

        case 200: // Left Bumper
            break;

        case 199: // Right Bumper
            break;

        case 201: // Left Trigger
            break;

        case 202: // Right Trigger
            break;

    }
});

这篇关于Xbox One 控制器输入到 UWP 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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