Skip to content

Instantly share code, notes, and snippets.

@adgedenkers
Last active April 2, 2024 14:02
Show Gist options
  • Save adgedenkers/219edca2850790f616dde3e5836865b9 to your computer and use it in GitHub Desktop.
Save adgedenkers/219edca2850790f616dde3e5836865b9 to your computer and use it in GitHub Desktop.
'''
File: mouse_automove2.py
Project: mouse_automove
Created Date: 2024-03-27
Author: Adge Denkers
Email: adge.denkers@gmail.com
-----
Last Modified: 2024-04-02
Modified By: Adge Denkers
Email: adge.denkers@gmail.com
-----
Description:
Automatically move the mouse 120 pixels in a random direction. Wait 3 minutes and then move the mouse again.
This keeps your screen alive until you type CTRL+C in your shell.
'''
import math
import pyautogui
import random
import time
# Function to move the mouse in a random direction and then back
def move_mouse_randomly():
angle = random.randint(0, 360) # Random angle in degrees
radians = math.radians(angle) # Convert angle to radians
# Calculate the change in x and y direction
dx = 120 * math.cos(radians)
dy = 120 * math.sin(radians)
# Get the current mouse position
start_x, start_y = pyautogui.position()
# Calculate the new position
end_x = start_x + dx
end_y = start_y + dy
# Move the mouse to the new position
pyautogui.moveTo(end_x, end_y)
# Move the mouse back to the original position
pyautogui.moveTo(start_x, start_y)
# Call the function to move the mouse
while True:
move_mouse_randomly()
time.sleep(180)
# Usage
# $ python mouse_automove2.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment