Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有可能;隆隆声;使用Python的Xbox 360控制器?_Python_Output_Xbox_Vibration - Fatal编程技术网

有没有可能;隆隆声;使用Python的Xbox 360控制器?

有没有可能;隆隆声;使用Python的Xbox 360控制器?,python,output,xbox,vibration,Python,Output,Xbox,Vibration,是否可以使用Python“隆隆”我的无线Xbox 360 PC控制器?我只找到了读取输入的解决方案,但找不到有关振动/隆隆声的信息 编辑: 根据@AdamRosenfield提供的代码,我得到了以下错误 Traceback (most recent call last): File "C:\Users\Usuario\Desktop\rumble.py", line 8, in <module> xinput = ctypes.windll.Xinput # Load

是否可以使用Python“隆隆”我的无线Xbox 360 PC控制器?我只找到了读取输入的解决方案,但找不到有关振动/隆隆声的信息

编辑:

根据@AdamRosenfield提供的代码,我得到了以下错误

Traceback (most recent call last):
  File "C:\Users\Usuario\Desktop\rumble.py", line 8, in <module>
    xinput = ctypes.windll.Xinput  # Load Xinput.dll
  File "C:\Python27\lib\ctypes\__init__.py", line 435, in __getattr__
    dll = self._dlltype(name)
  File "C:\Python27\lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found. 
回溯(最近一次呼叫最后一次):
文件“C:\Users\Usuario\Desktop\rumble.py”,第8行,在
xinput=ctypes.windell.xinput#加载xinput.dll
文件“C:\Python27\lib\ctypes\\ uuuu init\uuuuu.py”,第435行,在\uuu getattr中__
dll=self.\u dlltype(名称)
文件“C:\Python27\lib\ctypes\\uuuu init\uuuu.py”,第365行,在\uuu init中__
self.\u handle=\u dlopen(self.\u名称,模式)
WindowsError:[错误126]找不到指定的模块。

请注意,上一个错误是从西班牙语翻译过来的。

这是可能的,但并不容易。在C中,您将使用控制键来控制隆隆声。要从Python访问它,您必须编译一个用C编写的Python扩展,或者使用

类似的方法应该会起作用,但请记住我还没有测试过:

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, 1.0, 0.5)

感谢您的回答,我发现“ctypes.struct”有错误:它不是有效的属性。我也不知道“ctypes.struct”是从哪里来的@Belohlavek:哎呀,应该是
结构
,而不是
结构
。周末好项目+1@Belohlavek:是否已安装DirectX SDK?根据文档,XInput库只在默认情况下安装在WindowsVista和Windows8上。如果确实安装了DirectX SDK,但它仍然找不到DLL,则需要手动加载库,例如
xinput=ctypes.windell.LoadLibrary(r'C:\path\to\xinput.DLL')
。@Belohlavek:显然,实际的DLL名称中包含版本号。试着改用
ctypes.windell.xinput1\u 1
(或者
xinput1\u 3
或者
XInput9\u 1\u 0
,或者不管
C:\Windows\System32\xinput.dll的名称是什么)。