This repository has been archived by the owner on Feb 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (50 loc) · 1.57 KB
/
main.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
import pyautogui as pag
from tkinter import *
import random
import time
import threading
duration = 0.2 # duration of cursor movement & pressing key
interval = 10 # interval between cursor movements & pressing key
# New global variable to control key presses
key_press_running = False
def generate_random_coordinates():
x = random.randint(250, 375)
y = random.randint(375, 450)
return x, y
def press_random_key():
keys = ['w', 'a', 's', 'd']
pag.press(random.choice(keys))
def run_script():
while script_running:
x, y = generate_random_coordinates()
pag.moveTo(x, y, duration)
press_random_key() # press a random key
time.sleep(interval)
def toggle_script():
global script_running
script_running = not script_running
if script_running:
button.config(text="Stop")
# start script on other thread
script_thread = threading.Thread(target=run_script)
script_thread.start()
else:
button.config(text="Start")
def toggle_key_press():
global key_press_running
key_press_running = not key_press_running
# app window
root = Tk()
root.title("SuperPower")
root.geometry("150x80")
# frame for center
center_frame = Frame(root)
center_frame.pack(expand=True, fill="both")
# button to start/stop script
script_running = False
button = Button(center_frame, text="Start", command=toggle_script)
button.pack(pady=5)
# checkbox to toggle key press
key_checkbox = Checkbutton(center_frame, text="Toggle Key Press", command=toggle_key_press)
key_checkbox.pack(pady=5)
root.mainloop()