-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrandomMouseClickGUI.py
107 lines (82 loc) · 3.42 KB
/
randomMouseClickGUI.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
import tkinter as tk
import win32api
import win32con
import random
import time
defaultTime = 2
defaultInitialXCoordinate = 20
defaultInitialYCoordinate = 40
defaultFinalXCoordinate = 200
defaultFinalYCoordinate = 400
def setSleepTime(userInputTime):
print(f"time set to {userInputTime}")
def getTime():
defaultTime = timeEntry.get()
setSleepTime(defaultTime)
def getCoordinates():
defaultInitialXCoordinate = initialXCoordinateEntry.get()
defaultInitialYCoordinate = initialYCoordinateEntry.get()
defaultFinalXCoordinate = finalXCoordinateEntry.get()
defaultFinalYCoordinate = finalYCoordinateEntry.get()
setMouseRectangleCoordinates(defaultInitialXCoordinate,defaultInitialYCoordinate,defaultFinalXCoordinate,defaultFinalYCoordinate)
def setMouseRectangleCoordinates(initialXCoordinate,initialYCoordinate,finalXCoordinate,finalYCoordinate,):
print(f"cordinates set to {initialXCoordinate} {initialYCoordinate} {finalXCoordinate} {finalYCoordinate}")
def runMainScript():
while True:
win32api.SetCursorPos((random.randint(defaultInitialXCoordinate, defaultFinalXCoordinate), random.randint(defaultInitialYCoordinate, defaultFinalXCoordinate)))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, random.randint(1, 1000), random.randint(1, 1000), 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, random.randint(1, 1000), random.randint(1, 1000), 0, 0)
time.sleep(defaultTime)
def stopMainScript():
print('stopped!!!!')
exit()
root = tk.Tk()
root.title('Random Mouse Click')
frame = tk.Frame(root)
frame.size()
frame.pack()
timeLabel = tk.Label(frame, text="Enter Sleep Time (in seconds):")
timeEntry = tk.Entry(frame)
timeLabel.pack()
timeEntry.pack()
timeButton = tk.Button(frame,
text="SET SLEEP TIME",
fg="blue",
command=getTime)
timeButton.pack()
timeSettedLabel = tk.Label(frame, text=f"Time is set to {defaultTime} seconds")
timeSettedLabel.pack()
# INITIAL COORDINATES
# X COORDINATE
initialXCoordinateLabel = tk.Label(frame, text="Enter initial X coordinate:")
initialXCoordinateEntry = tk.Entry(frame)
initialXCoordinateLabel.pack()
initialXCoordinateEntry.pack()
# Y COORDINATE
initialYCoordinateLabel = tk.Label(frame, text="Enter initial Y coordinate:")
initialYCoordinateEntry = tk.Entry(frame)
initialYCoordinateLabel.pack()
initialYCoordinateEntry.pack()
# FINAL COORDINATES
# X COORDINATE
finalXCoordinateLabel = tk.Label(frame, text="Enter final X coordinate:")
finalXCoordinateEntry = tk.Entry(frame)
finalXCoordinateLabel.pack()
finalXCoordinateEntry.pack()
# Y COORDINATE
finalYCoordinateLabel = tk.Label(frame, text="Enter final Y coordinate:")
finalYCoordinateEntry = tk.Entry(frame)
finalYCoordinateLabel.pack()
finalYCoordinateEntry.pack()
# BUTTON
coordinateButton = tk.Button(frame,fg='blue',
text="SET CORDINATES",
command=getCoordinates)
coordinateButton.pack()
coordinateSettedLabel = tk.Label(frame,text=f"Coordiantes are set to initial x = {defaultInitialXCoordinate} y = {defaultInitialYCoordinate} and final x = {defaultFinalXCoordinate} y = {defaultFinalYCoordinate}")
coordinateSettedLabel.pack()
startScriptButton = tk.Button(frame,fg='green',text="Start Script",command=runMainScript)
startScriptButton.pack()
stopScriptButton = tk.Button(frame,fg='red',text="Stop Script",command=stopMainScript)
stopScriptButton.pack()
root.mainloop()