Pagini recente » Borderou de evaluare (job #162887) | Statistici Diana Boiangiu (DyaStar) | Atasamentele paginii Profil DyaStar | Atasamentele paginii Profil vladparau | Cod sursa (job #3368196)
import pyautogui
import random
import time
import keyboard
from screeninfo import get_monitors
Enable PyAutoGUI fail-safe as a backup (move mouse to top-left corner of primary screen)
pyautogui.FAILSAFE = True
def multi_screen_movement():
print("Multi-Screen Mouse Automation Started!")
print("--> Press 'Ctrl+Shift+Q' at any time to STOP the script. <--\n")
# Detect all connected monitors
monitors = get_monitors()
print(f"Detected {len(monitors)} monitor(s):")
for i, m in enumerate(monitors):
print(f" Screen {i + 1}: {m.width}x{m.height} (Offset X: {m.x}, Y: {m.y})")
print("-" * 50)
running = True
def stop_script():
nonlocal running
running = False
print("\nStop signal received! Winding down...")
# Register the hotkey shortcut
keyboard.add_hotkey('ctrl+shift+q', stop_script)
try:
while running:
# Cycle through each detected monitor one by one
for i, monitor in enumerate(monitors):
if not running:
break
print(f"\n--- Operating on Screen {i + 1} ---")
# Calculate the specific vertical center for this monitor
# m.y is the starting top coordinate, m.height // 2 is the middle point
center_y = monitor.y + (monitor.height // 2.5)
# Define left and right boundaries inside this specific monitor (10% margins)
margin = int(monitor.width * 0.1)
left_bound = monitor.x + margin
right_bound = monitor.x + monitor.width - margin
# Sweep Left -> Right
duration = random.uniform(1.0, 2.0)
print(f"Sweeping Left -> Right on Screen {i + 1}")
pyautogui.moveTo(right_bound, center_y, duration=duration)
if not running: break
# 50% chance to click at the right edge
if random.random() < 0.50:
time.sleep(random.uniform(0.1, 0.3))
pyautogui.click(button='left')
print(f" [Click] at ({right_bound}, {center_y})")
# Short break before sweeping back
time.sleep(random.uniform(0.5, 1.5))
# Sweep Right -> Left
duration = random.uniform(1.0, 2.0)
print(f"Sweeping Right -> Left on Screen {i + 1}")
pyautogui.moveTo(left_bound, center_y, duration=duration)
if not running: break
# 50% chance to click at the left edge
if random.random() < 0.50:
time.sleep(random.uniform(0.1, 0.3))
pyautogui.click(button='left')
print(f" [Click] at ({left_bound}, {center_y})")
# Responsive sleep loop before switching to the next screen
sleep_time = random.uniform(1.0, 3.0)
start_sleep = time.time()
while time.time() - start_sleep < sleep_time:
if not running:
break
time.sleep(0.1)
except pyautogui.FailSafeException:
print("\nScript stopped via PyAutoGUI Fail-Safe.")
finally:
keyboard.remove_all_hotkeys()
print("Script successfully terminated.")
if name == "main":
multi_screen_movement()