Xbox 360震动隆隆声?

2024-10-01 11:30:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经找到了一个脚本,启动Xbox360控制器隆隆(振动),但我无法让它关闭。有没有办法让它在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,)

谢谢


Tags: andtorightfunctionctypesleftvibrationcontroller
1条回答
网友
1楼 · 发布于 2024-10-01 11:30:55

看起来你已经把你需要的一切都准备好了。set_vibration helper函数接受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)

当然,这一切只是通过检查你的脚本,而不是测试

相关问题 更多 >