-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.py
147 lines (104 loc) · 3.19 KB
/
execute.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
import pyautogui
import time
import pickle
import os
import argparse
parser = argparse.ArgumentParser(description="Automate the Task")
parser.add_argument('-e','--picklefileName',required=True, help='Name of the pickle file which need to execute')
args = parser.parse_args()
filename=args.picklefileName
size=pyautogui.size()
listerner_status=True
flag=1
postions=[0,0]
inital=time.time()
click=1
button_select=1
try:
with open(filename, 'rb') as handle:
actions_performed = pickle.load(handle)
except Exception as e:
print("Oops File Doesn't Exist")
exit()
else:
print("Action Begins")
# print(actions_performed)
# exit()
key_flag=[]
button_number=1
def mouse_click(click):
pyautogui.click(x=click[1],y=click[2],button=click[3])
def mouse_scroll(click):
pyautogui.scroll(click[-1])
def mouse_move(click):
pyautogui.moveTo(click[1], click[2])
def double_click(click):
pyautogui.click(x=click[1],y=click[2],button=click[3])
pyautogui.doubleClick(x=click[1],y=click[2],button='left')
# pyautogui.doubleClick(x=click[1],y=click[2],button='left')
def key_release(click):
pyautogui.keyUp(click[1])
def mouse_drag(click):
pyautogui.click(x=(click[1]+click[3])/2,y=(click[2]+click[4])/2)
pyautogui.click(click[1],click[2])
pyautogui.dragTo(click[3], click[4], button='left')
def hotkey():
global key_flag
for i in key_flag:
if(i in ['ctrl','shift','alt','ctrl_r','shift_r','alt_r','tab']):
pyautogui.keyDown(i)
else:
pyautogui.press(i)
# for i in key_flag:
# pyautogui.keyUp(i)
return
def key_press(key):
global key_flag
if (key in ['ctrl','shift','alt','ctrl_r','shift_r','alt_r','tab']):
key_flag.append(key)
if('tab' in key_flag and len(key_flag)>0):
hotkey()
key_flag=[]
elif (key=='enter' and len(key_flag)==0):
pyautogui.press('enter')
elif (len(key_flag)>0 and len(key)>0):
try:
key_flag.append(eval(key))
except Exception as e:
key_flag.append(key)
hotkey()
key_flag=[]
elif(len(key_flag)==0 and len(key)>3):
pyautogui.press(key)
elif(len(key_flag)==0 and len(key)==1):
pyautogui.press(key)
elif(len(key_flag)==0 and len(key)==3):
pyautogui.press(eval(key))
else :
pyautogui.press(key)
return
for j,i in actions_performed.items():
if(i[0]=="mouse_click"):
mouse_click(i)
time.sleep(j)
if (i[0]=="mouse_scroll"):
mouse_scroll(i)
time.sleep(j)
# if (i[0]=="mouse_move"):
# mouse_move(i)
# time.sleep(j)
if(i[0]=="double_click"):
double_click(i)
time.sleep(j)
if(i[0]=="key_press" and i[1]!='esc'):
key_press(i[1])
time.sleep(j)
if(i[0]=="key_release"):
key_release(i)
time.sleep(j)
if (i[0]=="drag"):
mouse_drag(i)
time.sleep(j)
if(i[1]=='esc'):
break
#print("Action Stops ...")