Skip to content

Commit 6f894a0

Browse files
committed
first commit
1 parent 948f0f1 commit 6f894a0

File tree

7 files changed

+383
-0
lines changed

7 files changed

+383
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.txt

mousePlay.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import time
2+
import pyautogui
3+
import random
4+
5+
6+
def rightCord(xCord=None, yCord=None, pressTimes=1):
7+
pyautogui.rightClick(xCord, yCord, pressTimes)
8+
9+
10+
def clickCord(xCord=None, yCord=None, pressTimes=1):
11+
pyautogui.click(xCord, yCord, pressTimes)
12+
13+
14+
def moveCord(xCord=None, yCord=None, delay=0.1):
15+
pyautogui.moveTo(xCord, yCord, delay)
16+
17+
18+
# read cordFile and loop through each line
19+
def main():
20+
with open(cordFile+'.txt') as f:
21+
mode, sRange, eRange = map(int, f.readline().split(' '))
22+
if mode == 1:
23+
for line in f.readlines()[1:]:
24+
# print('hi')
25+
which, xCord, yCord, pressTimes = map(int, line.split())
26+
if which == 1:
27+
clickCord(xCord, yCord, pressTimes)
28+
elif which == 2:
29+
rightCord(xCord, yCord, pressTimes)
30+
elif mode == 2:
31+
print(sRange, eRange)
32+
# interval random float from sRange to eRange
33+
for line in f.readlines()[1:]:
34+
interval = random.uniform(sRange, eRange)
35+
print(interval)
36+
which, xCord, yCord, pressTimes = map(int, line.split())
37+
moveCord(xCord, yCord, interval)
38+
if which == 1:
39+
clickCord(xCord, yCord, pressTimes)
40+
elif which == 2:
41+
rightCord(xCord, yCord, pressTimes)
42+
elif mode == 3:
43+
reminder = 0
44+
for line in f.readlines()[1:]:
45+
which, xCord, yCord, interval, pressTimes = map(
46+
int, line.split())
47+
# 0.6 seconds is the default prefix time
48+
moveCord(xCord, yCord, interval - reminder - 0.6)
49+
if which == 1:
50+
clickCord(xCord, yCord, pressTimes)
51+
elif which == 2:
52+
rightCord(xCord, yCord, pressTimes)
53+
reminder = interval
54+
else:
55+
print('mode not found')
56+
57+
58+
if __name__ == '__main__':
59+
cordFile = 'mousePosition'
60+
timeSecs = int(input('program will run after (s) : '))
61+
startTime = time.time()
62+
# for timeSecs make countdown
63+
while time.time() - startTime < timeSecs:
64+
print(timeSecs - int(time.time() - startTime))
65+
time.sleep(1)
66+
main()
67+
endTime = int(time.time() - startTime)
68+
print('program runtime : ', endTime, 's')

mouseRec.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import win32api
2+
import win32con
3+
import time
4+
import pyautogui
5+
6+
7+
def writer(click):
8+
x, y = pyautogui.position()
9+
print('click recorded at: ' + str(x) + ', ' + str(y))
10+
time.sleep(0.1)
11+
with open(cordFile+'.txt', 'a') as f:
12+
f.write(str(click) + ' ' + str(x) + ' ' + str(y) + ' 1\n')
13+
time.sleep(0.1)
14+
15+
16+
def recorder(action):
17+
print('program ready to record | press Shift to STOP')
18+
# action = act
19+
# get state from virtual-key-codes
20+
while action:
21+
if (win32api.GetKeyState(0x01)) < 0:
22+
writer(1)
23+
elif (win32api.GetKeyState(0x02)) < 0:
24+
writer(2)
25+
elif (win32api.GetKeyState(0x10)) < 0:
26+
print('program stopped')
27+
action = False
28+
29+
30+
def realTimer(action):
31+
print('program ready to record | press Shift to STOP')
32+
# get state from virtual-key-codes
33+
rTime = time.time()
34+
print(rTime)
35+
while action:
36+
if (win32api.GetKeyState(0x01)) < 0:
37+
x, y = pyautogui.position()
38+
pTime = int(time.time() - rTime)
39+
print('click recorded at: ' + str(x) + ', ' + str(y))
40+
time.sleep(0.1)
41+
with open(cordFile+'.txt', 'a') as f:
42+
f.write('1 ' + str(x) + ' ' + str(y) +
43+
' ' + str(pTime) + ' 1\n')
44+
time.sleep(0.1)
45+
elif (win32api.GetKeyState(0x02)) < 0:
46+
x, y = pyautogui.position()
47+
pTime = int(time.time() - rTime)
48+
print('click recorded at: ' + str(x) + ', ' + str(y))
49+
time.sleep(0.1)
50+
with open(cordFile+'.txt', 'a') as f:
51+
f.write('2 ' + str(x) + ' ' + str(y) +
52+
' ' + str(pTime) + ' 1\n')
53+
time.sleep(0.1)
54+
elif (win32api.GetKeyState(0x10)) < 0:
55+
print('program stopped')
56+
break
57+
58+
59+
# delete the file if it exists
60+
def main():
61+
try:
62+
open(cordFile+'.txt', 'w').close()
63+
except:
64+
pass
65+
print(pyautogui.size()) # print screen size
66+
print('mode : [1] speed, [2] time-range, [3] real-time')
67+
mode = input('select mode : ')
68+
if mode == '1':
69+
print('speed mode selected')
70+
with open(cordFile+'.txt', 'a') as f:
71+
f.write('1 0 0\n')
72+
recorder(True)
73+
elif mode == '2':
74+
print('time range mode selected')
75+
sTime = input('start range (s) :')
76+
eTime = input('end range (s) :')
77+
timeRange = sTime + ' ' + eTime
78+
print('time range : ' + timeRange)
79+
with open(cordFile+'.txt', 'a') as f:
80+
f.write('2 ' + timeRange + '\n')
81+
recorder(True)
82+
elif mode == '3':
83+
print('real time mode selected')
84+
with open(cordFile+'.txt', 'a') as f:
85+
f.write('3 0 0\n')
86+
realTimer(True)
87+
else:
88+
print('error')
89+
exit()
90+
91+
92+
if __name__ == '__main__':
93+
cordFile = 'mousePosition'
94+
main()

mouseReplayer.ico

31.3 KB
Binary file not shown.

mouseReplayer.png

25.4 KB
Loading

readme.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Mouse Replayer
2+
3+
---
4+
5+
a simple mouse application that replays mouse events
6+
7+
let's automate boring tasks
8+
9+
## Usage :
10+
11+
0. Make mousePosition.txt
12+
1. Edit the mousePosition.txt file or record with in App > Record Mouse Function
13+
2. run the application select [2] to replay the mouse events
14+
15+
## Detail of mousePosition.txt:
16+
17+
- First Row are:
18+
- mode: [1] speed | [2] random time in range | [3] real time,
19+
- start range (optional, set to 0 if not used))
20+
- end range (optional, set to 0 if not used)
21+
- eg : 1 0 0
22+
- Second Row and so on:
23+
- Left click: 1 | right click: 2
24+
- x position
25+
- y position
26+
- time in seconds (optional for random and real time)
27+
- how many times of clicking
28+
- eg : 1 500 500 1
29+
30+
<!-- ## Installation : -->
31+
32+
<!-- 1. Windows
33+
34+
- Download [MouseReplayer.exe]()
35+
36+
2. Mac OS
37+
38+
- Download [MouseReplayer.app]()
39+
40+
3. Python Environment
41+
42+
- clone the [replayer]() repository -->
43+
44+
## Note :
45+
46+
THERES NO KEYLOGGER OR SUCH IN THIS APPLICATION

recordAndPlay.py

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
import win32api
2+
import win32con
3+
import time
4+
import pyautogui
5+
import random
6+
7+
8+
def writer(click):
9+
x, y = pyautogui.position()
10+
print('click recorded at: ' + str(x) + ', ' + str(y))
11+
time.sleep(0.1)
12+
with open(cordFile+'.txt', 'a') as f:
13+
f.write(str(click) + ' ' + str(x) + ' ' + str(y) + ' 1\n')
14+
time.sleep(0.1)
15+
16+
17+
def recorder(action):
18+
print('program ready to record | press Shift to STOP')
19+
# get state from virtual-key-codes
20+
while action:
21+
if (win32api.GetKeyState(0x01)) < 0:
22+
writer(1)
23+
elif (win32api.GetKeyState(0x02)) < 0:
24+
writer(2)
25+
elif (win32api.GetKeyState(0x10)) < 0:
26+
print('program stopped')
27+
action = False
28+
29+
30+
def realTimer(action):
31+
print('program ready to record | press Shift to STOP')
32+
# get state from virtual-key-codes
33+
rTime = time.time()
34+
print(rTime)
35+
while action:
36+
if (win32api.GetKeyState(0x01)) < 0:
37+
x, y = pyautogui.position()
38+
pTime = int(time.time() - rTime)
39+
print('click recorded at: ' + str(x) + ', ' + str(y))
40+
time.sleep(0.1)
41+
with open(cordFile+'.txt', 'a') as f:
42+
f.write('1 ' + str(x) + ' ' + str(y) +
43+
' ' + str(pTime) + ' 1\n')
44+
time.sleep(0.1)
45+
elif (win32api.GetKeyState(0x02)) < 0:
46+
x, y = pyautogui.position()
47+
pTime = int(time.time() - rTime)
48+
print('click recorded at: ' + str(x) + ', ' + str(y))
49+
time.sleep(0.1)
50+
with open(cordFile+'.txt', 'a') as f:
51+
f.write('2 ' + str(x) + ' ' + str(y) +
52+
' ' + str(pTime) + ' 1\n')
53+
time.sleep(0.1)
54+
elif (win32api.GetKeyState(0x10)) < 0:
55+
print('program stopped')
56+
break
57+
58+
59+
def Rec():
60+
# delete the file if it exists
61+
try:
62+
open(cordFile+'.txt', 'w').close()
63+
except:
64+
pass
65+
print(pyautogui.size()) # print screen size
66+
print('mode : [1] speed, [2] time-range, [3] real-time')
67+
mode = input('select mode : ')
68+
if mode == '1':
69+
print('speed mode selected')
70+
with open(cordFile+'.txt', 'a') as f:
71+
f.write('1 0 0\n')
72+
recorder(True)
73+
elif mode == '2':
74+
print('time range mode selected')
75+
sTime = input('start range (s) :')
76+
eTime = input('end range (s) :')
77+
timeRange = sTime + ' ' + eTime
78+
print('time range : ' + timeRange)
79+
with open(cordFile+'.txt', 'a') as f:
80+
f.write('2 ' + timeRange + '\n')
81+
recorder(True)
82+
elif mode == '3':
83+
print('real time mode selected')
84+
with open(cordFile+'.txt', 'a') as f:
85+
f.write('3 0 0\n')
86+
realTimer(True)
87+
else:
88+
print('error')
89+
exit()
90+
91+
92+
def rightCord(xCord=None, yCord=None, pressTimes=1):
93+
pyautogui.rightClick(xCord, yCord, pressTimes)
94+
95+
96+
def clickCord(xCord=None, yCord=None, pressTimes=1):
97+
pyautogui.click(xCord, yCord, pressTimes)
98+
99+
100+
def moveCord(xCord=None, yCord=None, delay=0.1):
101+
pyautogui.moveTo(xCord, yCord, delay)
102+
103+
104+
# read cordFile and loop through each line
105+
def Play():
106+
with open(cordFile+'.txt') as f:
107+
mode, sRange, eRange = map(int, f.readline().split(' '))
108+
if mode == 1:
109+
for line in f.readlines()[1:]:
110+
# print('hi')
111+
which, xCord, yCord, pressTimes = map(int, line.split())
112+
if which == 1:
113+
clickCord(xCord, yCord, pressTimes)
114+
elif which == 2:
115+
rightCord(xCord, yCord, pressTimes)
116+
elif mode == 2:
117+
print(sRange, eRange)
118+
# interval random float from sRange to eRange
119+
for line in f.readlines()[1:]:
120+
interval = random.uniform(sRange, eRange)
121+
print(interval)
122+
which, xCord, yCord, pressTimes = map(int, line.split())
123+
moveCord(xCord, yCord, interval)
124+
if which == 1:
125+
clickCord(xCord, yCord, pressTimes)
126+
elif which == 2:
127+
rightCord(xCord, yCord, pressTimes)
128+
elif mode == 3:
129+
reminder = 0
130+
for line in f.readlines()[1:]:
131+
which, xCord, yCord, interval, pressTimes = map(
132+
int, line.split())
133+
# 0.6 seconds is the default prefix time
134+
moveCord(xCord, yCord, interval - reminder - 0.6)
135+
if which == 1:
136+
clickCord(xCord, yCord, pressTimes)
137+
elif which == 2:
138+
rightCord(xCord, yCord, pressTimes)
139+
reminder = interval
140+
else:
141+
print('mode not found')
142+
143+
144+
def main():
145+
# by marvin zhong at github
146+
print('Welcome to the Mouse Replayer by Marvin Zhong at github')
147+
while True:
148+
print(
149+
'mode to select\t: [1] to record mouse event, [2] to replay your recorded mouse event')
150+
mode = input('select mode\t: ')
151+
if mode == '1':
152+
Rec()
153+
elif mode == '2':
154+
timeSecs = int(input('program will run after (s) : '))
155+
startTime = time.time()
156+
# for timeSecs make countdown
157+
while time.time() - startTime < timeSecs:
158+
print(timeSecs - int(time.time() - startTime))
159+
time.sleep(1)
160+
Play()
161+
endTime = int(time.time() - startTime)
162+
print('program runtime : ', endTime, 's')
163+
else:
164+
print('error')
165+
exit()
166+
print('do you want to close the program? [y/n]')
167+
close = input('close? : ')
168+
if close == 'y':
169+
break
170+
171+
172+
if __name__ == '__main__':
173+
cordFile = 'mousePosition'
174+
main()

0 commit comments

Comments
 (0)