Я попытался просмотреть все устройства, использующие win32com.client, и могу определить, какое устройство является джойстиком. затем я предположил, что pygame присваивает индексы в том порядке, в котором их находит win. Но это предположение было ошибочным. Вот фрагмент моего кода.
Код: Выделить всё
joystick_identifiers = {
"Logitech_F710": {
"vid": "046D",
"pid": "C21F",
},
}
def find_devices() -> list[dict]:
"""
Find all connected joysticks and return their information as a list of dictionaries.
Returns
-------
found_joysticks: list[dict]
A list of dictionaries containing joystick UID, name, index, VID, and PID.
"""
found_joysticks = []
wmi = win32com.client.GetObject("winmgmts:")
pygame.joystick.init() # Initialize the joystick module
# Initialize the joystick index to 0
jid = 0
# Iterate through all the joysticks in the identifiers and connect them to a device
for joystick_name, _ in joystick_identifiers.items():
vid = joystick_identifiers[joystick_name]["vid"]
pid = joystick_identifiers[joystick_name]["pid"]
for device in wmi.InstancesOf("Win32_PnPEntity"):
match = re.search(r"VID_([0-9A-F]+)&PID_([0-9A-F]+)\\([0-9A-F]+)", device.DeviceID, re.IGNORECASE)
if match:
port_vid, port_pid, port_uid = match.group(1), match.group(2), match.group(3)
if port_vid == vid and port_pid == pid:
found_joysticks.append(
{
"joystick_uid": port_uid,
"device_name": joystick_name,
"vid": port_vid,
"pid": port_pid,
"joystick_index": jid,
"device_address": device.DeviceID,
}
)
jid += 1
return found_joysticks
Подробнее здесь: https://stackoverflow.com/questions/792 ... -joysticks
Мобильная версия