2013-11-03 15 views
5

Kablosuz Xbox 360 denetleyicimi PC için Python ile "karıştırmak" mümkün mü? Sadece okuma için çözüm buldum ama titreşim/rumble hakkında bilgi bulamıyorum.Bir Xbox 360 denetleyicisini Python ile "karıştırmak" mümkün mü?

DÜZENLEME:

aşağıdaki hatayı alıyorum @AdamRosenfield tarafından sağlanan kodu takiben. son hata İspanyolca tercüme edildiğini

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. 

Plese notu.

cevap

4

Bu mümkün, ancak kolay değil. C'de, sesi kontrol etmek için XInputSetState() function'u kullanırdınız. Python'dan buna erişmek için, C dilinde yazılmış bir Python eklentisini derlemek veya ctypes library'u kullanmanız gerekir. Ayı akılda bu test değil ama böyle

şey, çalışması gerekir:

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) 
+0

teşekkürler, ben "ctypes.struct" ile hata alıyorum yanıtlayan için: Bu geçerli bir özellik değil. Ayrıca "ctypes.struct" in nereden geldiğini bilmiyorum! – Belohlavek

+0

@Belohlavek: Whoops, 'Yapı 'değil,' Yapı 'olmalıdır. –

+0

İyi hafta sonu projesi! +1 –

İlgili konular