Xbox One Controller input to UWP App

只谈情不闲聊 提交于 2019-12-20 04:59:26

问题


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 returns 0 for me even when I have my Xbox One controller switched on while the application is running on Xbox.

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.

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


回答1:


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;

    }
});


来源:https://stackoverflow.com/questions/37616821/xbox-one-controller-input-to-uwp-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!