-
Notifications
You must be signed in to change notification settings - Fork 0
/
amk.py
182 lines (176 loc) · 5 KB
/
amk.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import time
key=None
button=None
keyboard=None
mouse=None
def setupKeyboard():
global keyboard,key
from pynput.keyboard import Key, Controller
keyboard=Controller()
key=Key
def setupMouse():
global mouse,button
from pynput.mouse import Button, Controller
mouse = Controller()
button=Button
def getKey(inp):
if inp=='shift':
return key.shift
if inp=='enter':
return key.enter
if inp=='ctrl':
return key.ctrl
if inp=='cmd':
return key.cmd
else:
for k in key:
if str(k)[4:]==inp:
return k
return key.space
def getKey(inp):
if inp=='shift':
return key.shift
if inp=='enter':
return key.enter
if inp=='ctrl':
return key.ctrl
if inp=='cmd':
return key.cmd
else:
for k in key:
if str(k)[4:]==inp:
return k
return key.space
def execute(lines):
nextconfig=''
for line in lines:
if line=='' or line[0]=='#':
continue
if line[-1]=='\n':
line=line[:-1]
if line.startswith('type:'):
try:
a=line[5:]
#print('typing',a)
keyboard.type(a)
except:
pass
#print("can't execute" ,line)
elif line.startswith('sleep:'):
try:
a=line[6:]
#print('sleeping',a)
time.sleep(float(a))
except:
pass
#print("can't execute" ,line)
elif line.startswith('down:'):
try:
a=line[5:]
#print('pressing',a)
if len(a)==1:
keyboard.press(a)
else:
keyboard.press(getKey(a))
except:
pass
#print("can't execute" ,line)
elif line.startswith('up:'):
try:
a=line[3:]
#print('releasing',a)
if len(a)==1:
keyboard.release(a)
else:
keyboard.release(getKey(a))
except:
pass
#print("can't execute" ,line)
elif line.startswith('goto:'):
try:
a=line[5:]
x=int(a[:a.index(',')])
y=int(a[a.index(',')+1:])
mouse.position=(x,y)
#print('going to',x,',',y)
except:
pass
#print("can't execute" ,line)
elif line.startswith('move:'):
try:
a=line[5:]
x=int(a[:a.index(',')])
y=int(a[a.index(',')+1:])
mouse.move(x,y)
#print('moving by',x,',',y)
except:
pass
#print("can't execute" ,line)
elif line=='click:left':
try:
mouse.click(button.left)
#print('left clicking (on mouse)')
except:
pass
#print("can`t execute" ,line)
elif line=='click:right':
try:
mouse.click(button.right)
#print('right clicking (on mouse)')
except:
pass
#print("can`t execute" ,line)
elif line=='click:middle':
try:
mouse.click(button.middle)
#print('middle clicking (on mouse)')
except:
pass
#print("can`t execute" ,line)
elif line=='mousedown:left':
try:
mouse.press(button.left)
#print('mousedown left')
except:
pass
#print("can't execute" ,line)
elif line=='mouseup:left':
try:
mouse.release(button.left)
#print('mouseup left')
except:
pass
#print("can't execute" ,line)
elif line=='mousedown:right':
try:
mouse.press(button.right)
#print('mousedown right')
except:
pass
#print("can't execute" ,line)
elif line=='mouseup:right':
try:
mouse.release(button.right)
#print('mouseup right')
except:
pass
#print("can't execute" ,line)
elif line=='mousedown:middle':
try:
mouse.press(button.middle)
#print('mousedown middle')
except:
pass
#print("can't execute" ,line)
elif line=='mouseup:middle':
try:
mouse.release(button.middle)
#print('mouseup middle')
except:
pass
#print("can't execute" ,line)
elif line=='exit':
exit()
elif line.startswith('<') :
nextconfig=line[1:]
return nextconfig