-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcursorwalk.py
More file actions
executable file
·68 lines (55 loc) · 1.68 KB
/
cursorwalk.py
File metadata and controls
executable file
·68 lines (55 loc) · 1.68 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
#!/usr/bin/env python3
import sys
import signal
import random
import time
import argparse
import pyautogui
pyautogui.FAILSAFE = False
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--stepsize", default=10, type=int, help="pixel stepsize")
parser.add_argument(
"-r", "--ratespeed", default=0.2, type=float, help="seconds between each pixel move"
)
parser.add_argument(
"-t",
"--timeout",
default=0,
type=float,
help="timeout for idle mouse to start random walk (seconds)",
)
args = parser.parse_args()
stepsize = abs(args.stepsize)
speed = abs(args.ratespeed)
timeout = abs(args.timeout)
def startwalk(stepsize, speed):
while True:
x = pyautogui.position()[0]
y = pyautogui.position()[1]
step = random.randrange(5)
if step == 0:
pyautogui.moveTo(x + stepsize, y, duration=speed)
elif step == 1:
pyautogui.moveTo(x - stepsize, y, duration=speed)
elif step == 2:
pyautogui.moveTo(x, y + stepsize, duration=speed)
elif step == 3:
pyautogui.moveTo(x, y - stepsize, duration=speed)
if (
x - pyautogui.position()[0] > stepsize
or y - pyautogui.position()[1] > stepsize
):
break
def signal_handler(sig, frame):
sys.exit(0)
def main():
signal.signal(signal.SIGINT, signal_handler)
while True:
x = pyautogui.position()[0]
y = pyautogui.position()[1]
time.sleep(timeout)
if x == pyautogui.position()[0] and pyautogui.position()[1]:
startwalk(stepsize, speed)
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal_handler)
main()