| 1 | """Print the details of all available input devices to stdout. |
| 2 | """ |
| 3 | import pyglet |
| 4 | |
| 5 | window = pyglet.window.Window() |
| 6 | devices = pyglet.input.get_devices() |
| 7 | |
| 8 | |
| 9 | def watch_control(device, control): |
| 10 | @control.event |
| 11 | def on_change(value): |
| 12 | print(f'{device!r}: {control!r}.on_change({value!r})') |
| 13 | |
| 14 | if isinstance(control, pyglet.input.base.Button): |
| 15 | @control.event |
| 16 | def on_press(): |
| 17 | print(f"{device!r}: {control!r}.on_press()") |
| 18 | |
| 19 | @control.event |
| 20 | def on_release(): |
| 21 | print(f'{device!r}: {control!r}.on_release()') |
| 22 | |
| 23 | |
| 24 | print('Devices:') |
| 25 | for device in devices: |
| 26 | print(' ', device.name, end=' ') |
| 27 | try: |
| 28 | device.open(window=window) |
| 29 | print('OK') |
| 30 | |
| 31 | for control in device.get_controls(): |
| 32 | print(' ', control.name) |
| 33 | watch_control(device, control) |
| 34 | |
| 35 | except pyglet.input.DeviceException: |
| 36 | print('Fail') |
| 37 | |
| 38 | pyglet.app.run() |