-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathremote.py
45 lines (41 loc) · 916 Bytes
/
remote.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
import string
import sys
import os
from evdev import InputDevice
from select import select
device = InputDevice('/dev/input/event0')
keys = {
'2': '1',
'3': '2',
'4': '3',
'5': '4',
'6': '5',
'7': '6',
'8': '7',
'9': '8',
'10': '9',
'11': '0',
'71': '7',
'72': '8',
'73': '9',
'75': '4',
'76': '5',
'77': '6',
'79': '1',
'80': '2',
'81': '3',
};
def get_key(event):
code = str(event.code)
if event.type == 1 and event.value == 1 and code in keys:
return keys[str(event.code)]
return None
while True:
r, w, x = select([device], [], [])
for event in device.read():
if event.type == 1 and event.value == 1:
sys.stderr.write('Key code: ' + str(event.code) + '\n')
key = get_key(event)
if (key != None):
sys.stdout.write(key + '\n')
sys.stdout.flush()