-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadKeys.py
executable file
·44 lines (35 loc) · 1000 Bytes
/
ReadKeys.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
#!/usr/local/bin/python3
import evdev
import time
from evdev import ecodes
from select import select
from inputEventCreator import add_input_to_queue, process_queue
import asyncio
deviceName = "DaKai 2.4G RX"
kbds = []
# Load all the relevant devices
allDevices = [evdev.InputDevice(dv) for dv in evdev.list_devices()]
for dev in allDevices:
if deviceName in dev.name:
kbds.append(dev)
# Make this program the exclusive handler of this device
dev.grab()
# Define an asynchronous event handler
async def add_events(device):
async for event in device.async_read_loop():
if event.type == 1 and event.value < 2:
add_input_to_queue(event)
async def procQ():
while True:
process_queue()
await asyncio.sleep(0.05)
for dev in kbds:
asyncio.ensure_future(add_events(dev))
asyncio.ensure_future(procQ())
loop = asyncio.get_event_loop()
try:
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
loop.close()