fenrir/play zone/consumeEvents.py

48 lines
1.1 KiB
Python
Raw Normal View History

2016-08-09 20:09:49 -04:00
#!/bin/python
import evdev
from evdev import InputDevice, UInput
from select import select
import time
iDevices = map(evdev.InputDevice, (evdev.list_devices()))
2016-08-11 08:37:46 -04:00
iDevices = {dev.fd: dev for dev in iDevices if 1 in dev.capabilities()}
2016-08-09 20:09:49 -04:00
uDevices = {}
for fd in iDevices:
dev = iDevices[fd]
2016-08-11 08:37:46 -04:00
cap = dev.capabilities()
del cap[0]
uDevices[fd] = UInput(
cap,
dev.name,
dev.info.vendor,
2016-08-09 20:09:49 -04:00
# dev.info.product,
# dev.version,
# dev.info.bustype,
2016-08-11 08:37:46 -04:00
# '/dev/uinput'
)
2016-08-09 20:09:49 -04:00
i = 0
2016-09-12 18:05:29 -04:00
while i < 1000:
2016-08-09 20:09:49 -04:00
r, w, x = select(iDevices, [], [])
if r != []:
i += 1
for fd in r:
for event in iDevices[fd].read():
2016-08-11 08:37:46 -04:00
if event.code != 30: # a
2016-09-12 18:05:29 -04:00
print('Devicename:'+ iDevices[fd].name + ' Devicepath:' + iDevices[fd].fn + ' Events:' + str(iDevices[fd].active_keys(verbose=True)) + ' Value:' + str(event.value))
2016-08-11 08:37:46 -04:00
else:
print('this key is consumed')
2016-09-12 18:05:29 -04:00
break
break
2016-08-09 20:09:49 -04:00
for fd in iDevices:
2016-08-11 08:37:46 -04:00
iDevices[fd].close()
uDevices[fd].close()
iDevices.clear()
uDevices.clear()
2016-08-09 20:09:49 -04:00