-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserV2.py
More file actions
108 lines (96 loc) · 2.67 KB
/
serV2.py
File metadata and controls
108 lines (96 loc) · 2.67 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import os
import serial
import subprocess
ser = serial.Serial('/dev/ttyUSB0')
old={'z':0, 'x':0, 'c':0, 'v':0, 'b':0, 'n':0,'1':0, 'KP_Enter':0, 'Up':0, 'Down':0, 'Left':0, 'Right':0}
def click(old_bit, new_bit, key):
if old_bit is 1 and new_bit is 0:
press_os(key, 0)
elif old_bit is 0 and new_bit is 1:
press_os(key, 1)
def click_l(old_bit, new_bit, key):
if old_bit is 0 and new_bit is 1:
subprocess.Popen(["xdotool", 'key', key])
def check(pos,bit):
if pos is 4:
try:
click(old['z'], bit, 'z')
except:
pass
elif pos is 5:
try:
click(old['x'], bit, 'x')
except:
pass
elif pos is 6:
try:
click(old['c'], bit, 'c')
except:
pass
elif pos is 7:
try:
click(old['KP_Enter'], bit, 'KP_Enter')
except:
pass
elif pos is 0:
try:
click(old['Up'], bit, 'Up')
except:
pass
elif pos is 1:
try:
click(old['Down'], bit, 'Down')
except:
pass
elif pos is 2:
try:
click(old['Left'], bit, 'Left')
except:
pass
elif pos is 3:
try:
click(old['Right'], bit, 'Right')
except:
pass
elif pos is 8:
try:
click(old['v'], bit, 'v')
except:
pass
elif pos is 9:
try:
click(old['b'], bit, 'b')
except:
pass
elif pos is 10:
try:
click(old['n'], bit, 'n')
except:
pass
elif pos is 11:
try:
click(old['1'], bit, '1')
except:
pass
else:
pass
def func(num, pos):
return (num & (1 << pos)) >> pos
def press_os(key, byte):
if byte:
subprocess.Popen(["xdotool", 'keydown', key])
old[key] = 1
'''print 'press '+key'''
else:
subprocess.Popen(["xdotool", 'keyup', key])
old[key] =0
'''print 'up ' + key'''
temp=[0]*12
while 1:
s="".join(ser.readline().splitlines())
try:
n=int(s)
for pos in xrange(len(temp)):
check(pos,func(n, pos))
except:
pass