【问题标题】:How to split triggers on XBOX One controllers?如何在 XBOX One 控制器上拆分触发器?
【发布时间】:2017-05-15 15:14:02
【问题描述】:

我希望能够独立检测扳机拉动,但扳机似乎共享一个轴。

我在 MSDN 文档中没有看到有关 Xbox One 控制器的任何内容,但对于 Xbox 360 控制器,DirectInput 触发器共享轴,而 XInput 为每个触发器提供单独的轴。这表明 pygame 使用的是 DirectInput 而不是 Xinput,但我不知道如何强制 pygame 使用 Xinput。

(如何)我可以强制 pygame 使用 xinput 而不是直接输入? 如果这真的不可行,我愿意使用不同的语言。

我正在使用这个脚本从控制器读取输入:

import pygame
pygame.init()

screen = pygame.display.set_mode((400,400))
joysticks = []

for i in range(0, pygame.joystick.get_count()):
    joysticks.append(pygame.joystick.Joystick(i))
    joysticks[-1].init()

while True:
    for event in pygame.event.get():
        print event

编辑:我现在没有时间完整地写出来,但与此同时,我发现这段代码似乎对我有用(在 Xbox One Spectra 控制器上):https://github.com/r4dian/Xbox-360-Controller-for-Python

【问题讨论】:

    标签: python pygame xbox-one


    【解决方案1】:

    第一:

    来自https://en.wikipedia.org/wiki/DirectInput#DirectInput_vs_XInput

    截至 2011 年,XInput 适用于 Xbox 360 控制器,而 DirectInput 适用于任何控制器

    第二:

    Pygame 是一个 SDL 绑定。

    所以如果SDL 有,pygame 可以有XInput 支持。可悲的是,SDL 没有。 原因是我之前写的,DirectInput比较受欢迎。 另请查看: http://forums.libsdl.org/viewtopic.php?t=6352&sid=35bdc1b1615f9ea081671ff548a7e360

    如果你愿意,你仍然可以在 XInput API 周围写一个包装器。

    编辑:

    您链接的存储库使用 ctypes 围绕 XInput API 创建一个包装器。

    【讨论】:

    • 感谢您的帮助!
    猜你喜欢
    • 2016-03-09
    • 2015-03-23
    • 2015-03-19
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 2015-11-05
    • 2018-12-10
    • 2018-12-21
    相关资源
    最近更新 更多