-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecorder.py
More file actions
147 lines (140 loc) · 5.74 KB
/
Recorder.py
File metadata and controls
147 lines (140 loc) · 5.74 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
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 pynput
from time import time,sleep
from threading import Thread as th
from numpy import NaN
from Window import window
from Position import pos as Position
import logging
from math import ceil
class recorder():
def __init__(self,mouse=None,keyboard=None):
self.p=Position()
self.statu="stop"
self.Track=None
if mouse==None:
self.mouse=pynput.mouse.Controller()
else:
self.mouse=mouse
if keyboard==None:
self.keyboard=pynput.keyboard.Controller()
else:
self.keyboard=keyboard
self.w=window()
self.listen=[pynput.mouse.Listener(on_move=self.m_move, on_click=self.m_click, on_scroll=self.m_scroll),
pynput.keyboard.Listener(on_press=self.k_press,on_release=self.k_release)]
self.listen[0].start()
self.listen[1].start()
def put_track(self,Track):
self.Track=Track
self.t0=time()
def start(self,df=None):
if type(df)!=type(None):
self.put_track(df)
if self.statu=="stop" and type(self.Track)!=type(None):
logging.info("recorder statu to run")
index = self.Track[self.Track["type"] == "click"].index
self.lastTimeBeforeRec = self.Track[self.Track["type"] == "click"].index.shape[0]
if "autorel" in self.Track.param["tasks"]:
self.Track.relto(self.w.get_top()[1],self.w.get_rect())
if self.Track.shape[0]>1:
self.t0=time()-self.Track.index.max()
else:
self.t0=time()
self.statu="run"
def __del__(self):
self.listen[0].stop()
self.listen[1].stop()
def stop(self):
if self.statu=="run":
logging.warning("Recorder Stoped")
self.statu="stop"
self.Track.remove_solo()
self.Track.del_click(-1, "after")
LTBFR = ceil(self.lastTimeBeforeRec/2)
if self.lastTimeBeforeRec:
self.Track.del_click([LTBFR, LTBFR+1], "drop")
else:
self.Track.del_click(LTBFR, "before")
self.Track.remove_move()
return True
return False
def m_click(self,x, y, button, pressed):
if self.statu=="run":
logging.info("clicked")
x,y=self.mouse.position
t=time()-self.t0
self.Track.loc[t]=NaN
self.Track.at[t, "type"]="click"
self.Track.at[t, "x1"]=x
self.Track.at[t, 'y1']=y
self.Track.at[t, "button"]=button
if pressed:
self.Track.at[t, "stat"]=True
if "screenshot" in self.Track.param["tasks"]:
self.Track.loc[t+0.0001]=NaN
self.Track["type"][t+0.0001]="screenshot"
self.Track["data"][t+0.0001]=self.w.screenShot()# To change, array not supported in cells
else:
self.Track.at[t, "stat"]=False
if "screenshot" in self.Track.param["tasks"]:
self.Track.loc[t+0.0001]=NaN
self.Track.at[t+0.0001, "type"]="screenshot"
self.Track.at[t+0.0001, "data"]=self.w.screenShot()
if "autorel" in self.Track.param["tasks"]:
#self.Track.relto(self.w.get_top()[1],self.w.get_rect())
n,title,exeName=self.w.get_top()
Condition = self.Track[self.Track["type"]=="relto"]
#print("condition",Condition)
if Condition.shape[0]==1:
ind=0
elif Condition.shape[0]!=0:
ind=Condition.shape[0]-1
if title=='':
self.Track.NotRel()
logging.warning("Access denided to window "+title+" so set relative to screen size")
elif (Condition.shape[0]==0) or (not (title in Condition["info"][Condition.index[ind]])):
#### condition pour tester les autorisations
print("Condition at release Ok")
if self.w.test(n):
self.Track.relto(title,self.w.get_rect(n),exeName=exeName)
logging.info("relative "+str(t)+": "+title)
else:
self.Track.NotRel()
logging.warning("Access denided to window "+title+" so set relative to screen size")
def m_move(self,x, y):
if self.statu=="run":
x,y=self.mouse.position
t=time()-self.t0
self.Track.loc[t]=NaN
self.Track.at[t, "type"]="move"
self.Track.at[t, "x1"]=x
self.Track.at[t, "y1"]=y
def m_scroll(self,x, y, dx, dy):
if self.statu=="run":
x,y=self.mouse.position
t=time()-self.t0
self.Track.loc[t]=NaN
self.Track.at[t, "type"]="scroll"
self.Track.at[t, "x1"]=x
self.Track.at[t, "y1"]=y
self.Track.at[t, "x2"]=dx
self.Track.at[t, "y2"]=dy
def k_press(self,key):
if self.statu=="run":
t=time()-self.t0
self.Track.loc[t]=NaN
self.Track.at[t, "type"]="key"
self.Track.at[t, "button"]=key
self.Track.at[t, "stat"]=True
def k_release(self,key):
if self.statu=="run":
t=time()-self.t0
self.Track.loc[t]=NaN
self.Track.at[t, "type"]="key"
self.Track.at[t, "button"]=key
self.Track.at[t, "stat"]=False
if __name__=="__main__":
from Track import Track
a=recorder()
t=Track()
a.start(t)