-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputdevice.py
63 lines (46 loc) · 1.77 KB
/
inputdevice.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import evdev
def list_devices():
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
input_devices = []
for device in devices:
input_devices.append(InputDevice(device))
return input_devices
def from_json(json):
devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
for device in devices:
if device.name == json['name'] and device.phys == json['phys'] and device.version == json['version'] and device.info.vendor == json['vendor'] and device.info.product == json['product']:
return InputDevice(device)
return None
class InputDevice:
def __init__(self, device):
self.device = device
def name(self):
return self.device.name
def path(self):
return self.device.path
def info_string(self):
return self.device.name + " " + self.device.phys + " " + str(self.device.info.vendor) + " " + str(self.device.info.product) + " " + str(self.device.version) + " [" + self.device.path + "]"
def capabilities(self):
return self.device.capabilities(absinfo=False)
def vendor(self):
return self.device.info.vendor
def version(self):
return self.device.version
def product(self):
return self.device.info.product
def grab(self):
return self.device.grab()
def ungrab(self):
return self.device.ungrab()
def read_loop(self):
return self.device.read_loop()
def close(self):
return self.device.close()
def to_dict(self):
data = dict()
data['name'] = self.device.name
data['phys'] = self.device.phys
data['version'] = self.device.version
data['vendor'] = self.device.info.vendor
data['product'] = self.device.info.product
return data