56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
import os
|
|
import pygame
|
|
from evdev import InputDevice, list_devices
|
|
|
|
def format_vidpid(info):
|
|
return f"{info.vendor:04x}:{info.product:04x}"
|
|
|
|
def get_evdev_devices():
|
|
evdev_devices = {}
|
|
for path in list_devices():
|
|
try:
|
|
dev = InputDevice(path)
|
|
evdev_devices[os.path.basename(path)] = {
|
|
'name': dev.name,
|
|
'phys': dev.phys,
|
|
'vidpid': format_vidpid(dev.info),
|
|
'path': path
|
|
}
|
|
except Exception:
|
|
pass
|
|
return evdev_devices
|
|
|
|
def match_evdev_to_pygame():
|
|
pygame.init()
|
|
pygame.joystick.init()
|
|
|
|
evdev_devices = get_evdev_devices()
|
|
|
|
for i in range(pygame.joystick.get_count()):
|
|
js = pygame.joystick.Joystick(i)
|
|
js.init()
|
|
name = js.get_name()
|
|
guid = js.get_guid()
|
|
|
|
# Try to guess the matching evdev device based on name
|
|
matched = None
|
|
for ev in evdev_devices.values():
|
|
if name.lower() in ev['name'].lower() or ev['name'].lower() in name.lower():
|
|
matched = ev
|
|
break
|
|
|
|
print(f"Joystick {i}:")
|
|
print(f" pygame name : {name}")
|
|
print(f" pygame guid : {guid}")
|
|
if matched:
|
|
print(f" evdev name : {matched['name']}")
|
|
print(f" path : {matched['path']}")
|
|
print(f" phys : {matched['phys']}")
|
|
print(f" VID:PID : {matched['vidpid']}")
|
|
else:
|
|
print(f" evdev info : [not matched]")
|
|
print("-" * 40)
|
|
|
|
if __name__ == "__main__":
|
|
match_evdev_to_pygame()
|