File: input.py

package info (click to toggle)
pyglet 1.5.27%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,356 kB
  • sloc: python: 98,028; ansic: 171; makefile: 148; sh: 9
file content (46 lines) | stat: -rwxr-xr-x 1,050 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python

"""Print the details of all available input devices to stdout.
"""

from __future__ import print_function

__docformat__ = 'restructuredtext'
__version__ = '$Id: $'

import pyglet

window = pyglet.window.Window()
devices = pyglet.input.get_devices()


def watch_control(device, control):
    @control.event
    def on_change(value):
        print('%r: %r.on_change(%r)' % (device, control, value))

    if isinstance(control, pyglet.input.base.Button):
        @control.event
        def on_press():
            print('%r: %r.on_press()' % (device, control))

        @control.event
        def on_release():
            print('%r: %r.on_release()' % (device, control))


print('Devices:')
for device in devices:
    print('  ', device.name, end=' ')
    try:
        device.open(window=window)
        print('OK')

        for control in device.get_controls():
            print('    ', control.name)
            watch_control(device, control)

    except pyglet.input.DeviceException:
        print('Fail')

pyglet.app.run()