-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIdleAssistant.pyw
134 lines (112 loc) · 4.02 KB
/
IdleAssistant.pyw
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
import pyautogui
import keyboard
import random
import time
import threading
from pystray import Icon, MenuItem, Menu
from PIL import Image, ImageDraw
import os
import sys
# Flag to control the script running state
running = True
def random_mouse_movement():
"""Randomly move the mouse every few seconds."""
screen_width, screen_height = pyautogui.size()
while running:
x = random.randint(0, screen_width - 1)
y = random.randint(0, screen_height - 1)
pyautogui.moveTo(x, y, duration=random.uniform(0.1, 0.5))
time.sleep(random.uniform(1, 5))
def random_alt_tab():
"""Randomly perform Alt+Tab."""
while running:
pyautogui.hotkey('alt', 'tab')
time.sleep(random.uniform(10, 30))
def random_ctrl_tab():
"""Randomly perform Ctrl+Tab."""
while running:
pyautogui.hotkey('ctrl', 'tab')
time.sleep(random.uniform(15, 45))
def random_keystrokes():
"""Randomly perform keystrokes."""
keys = ['a', 's', 'd', 'f', 'q', 'w', 'e', 'r', 't', 'y', '1', '2', '3', '4', 'space']
while running:
random_key = random.choice(keys)
pyautogui.press(random_key)
time.sleep(random.uniform(5, 15))
def monitor_exit():
"""Monitors for the ESC key press to exit the script."""
global running
while running:
if keyboard.is_pressed('esc'):
running = False
break
time.sleep(0.1)
def stop_script(icon, item):
"""Stop the script and exit."""
global running
running = False
icon.stop()
def restart_script(icon, item):
"""Restart the script."""
global running
running = False
icon.stop()
# Restart the script
os.execv(sys.executable, ['python'] + sys.argv)
def random_left_click():
"""Randomly perform left mouse clicks at random positions."""
screen_width, screen_height = pyautogui.size()
while running:
x = random.randint(0, screen_width - 1)
y = random.randint(0, screen_height - 1)
pyautogui.click(x, y) # Perform a left click
time.sleep(random.uniform(2, 5)) # Wait for a random interval before the next click
def setup_tray_icon():
"""Create a system tray icon."""
# Get the directory of the current script
base_dir = os.path.dirname(os.path.abspath(__file__))
# Load the icon image from file using the dynamic path
icon_image = Image.open(os.path.join(base_dir, "icon.ico"))
# Create a menu for the tray icon with Exit and Restart options
menu = Menu(
MenuItem('Restart', restart_script), # Add Restart option
MenuItem('Exit', stop_script) # Add Exit option
)
# Create the tray icon
icon = Icon("Idle Assistant", icon_image, "Idle Assistant", menu)
return icon
def start_background_tasks():
"""Start background tasks."""
# Threads for each task
mouse_thread = threading.Thread(target=random_mouse_movement)
alt_tab_thread = threading.Thread(target=random_alt_tab)
ctrl_tab_thread = threading.Thread(target=random_ctrl_tab)
keystrokes_thread = threading.Thread(target=random_keystrokes)
click_thread = threading.Thread(target=random_left_click)
exit_thread = threading.Thread(target=monitor_exit)
# Start all threads
mouse_thread.start()
alt_tab_thread.start()
ctrl_tab_thread.start() # Start Ctrl+Tab thread
keystrokes_thread.start()
click_thread.start()
exit_thread.start()
# Wait for all threads to finish
mouse_thread.join()
alt_tab_thread.join()
ctrl_tab_thread.join() # Wait for Ctrl+Tab thread
keystrokes_thread.join()
click_thread.join()
exit_thread.join()
# Main function to run the tray icon and background tasks
def main():
# Setup the system tray icon
tray_icon = setup_tray_icon()
# Start the background tasks in a separate thread
background_thread = threading.Thread(target=start_background_tasks)
background_thread.start()
# Run the system tray icon (this will block until the icon is stopped)
tray_icon.run()
if __name__ == "__main__":
main()