Xbox 360震动反馈?

4

我已经找到了一个启动Xbox 360手柄震动的脚本,但是我无法让它停止。有没有一种方法可以在5秒后停止震动?

import ctypes

# Define necessary structures
 class XINPUT_VIBRATION(ctypes.Structure):
    _fields_ = [("wLeftMotorSpeed", ctypes.c_ushort),
                ("wRightMotorSpeed", ctypes.c_ushort)]

xinput = ctypes.windll.xinput1_1  # Load Xinput.dll

# Set up function argument types and return type
XInputSetState = xinput.XInputSetState
XInputSetState.argtypes = [ctypes.c_uint, ctypes.POINTER(XINPUT_VIBRATION)]
XInputSetState.restype = ctypes.c_uint

# Now we're ready to call it.  Set left motor to 100%, right motor to 50%
# for controller 0
vibration = XINPUT_VIBRATION(65535, 32768)
XInputSetState(0, ctypes.byref(vibration))

# You can also create a helper function like this:
def set_vibration(controller, left_motor, right_motor):
    vibration = XINPUT_VIBRATION(int(left_motor * 65535), int(right_motor * 65535))
    XInputSetState(controller, ctypes.byref(vibration))

# ... and use it like so
set_vibration(0, 0.5, 0.5,)

谢谢


3
你尝试过使用set_vibration(0, 0, 0)吗? - Tyler
1个回答

3
看起来你现在就拥有了这个脚本所需的一切。set_vibration助手函数接受3个输入参数:
  • 控制器id(在你的情况下为0)
  • 左电机振动强度从0(关闭)到1.0(开启全力)- 你使用0.5将其设置为50%
  • 右电机振动强度(同样是0-1.0)
因此,要将它设置为50%功率仅震动5秒钟,请尝试以下操作:
import time
set_vibration(0, 0.5, 0.5)
time.sleep(5)
set_vibration(0, 0, 0)

毫无疑问,这些只是通过检查你的脚本得出的结论,并没有经过测试。


嗨,谢谢,那个方法可行。现在看着它,我以为会更复杂些。我现在想将震动(这个脚本)分配给事件触发器,这样当按下Xbox 360控制器上的左摇杆时,手柄就会播放此脚本并震动。 - RKEONECS

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接