import pyautogui import time import random # Define a function to move the mouse in a random direction for a random length def move_mouse(): while True: # Get the current mouse position x, y = pyautogui.position() # Generate a random length between 1 and 100 length = random.randint(1, 100) # Generate a random direction direction = random.choice(['up', 'down', 'left', 'right']) # Move the mouse in the chosen direction if direction == 'up': y -= length elif direction == 'down': y += length elif direction == 'left': x -= length else: # direction == 'right' x += length # Generate a random duration between 0.1 and 1 second duration = random.uniform(0.1, 1) # Move the mouse to the new position pyautogui.moveTo(x, y, duration=duration) print(f"Moved the mouse {length} pixels {direction} in {duration} seconds.") # Wait for 20 seconds time.sleep(20) # Call the function move_mouse()