Skip to content

Instantly share code, notes, and snippets.

@adgedenkers
Last active April 3, 2024 11:55
Show Gist options
  • Save adgedenkers/7ba7de54b14580f6e3874d0df2b52e60 to your computer and use it in GitHub Desktop.
Save adgedenkers/7ba7de54b14580f6e3874d0df2b52e60 to your computer and use it in GitHub Desktop.
'''
File: mouse_move3.py
Project: auto-move mouse
Created Date: 2024-03-27
Author: Adge Denkers
Email: adge.denkers@gmail.com
-----
Last Modified: 2024-04-03
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 time
def standard_spiral():
while True:
# set starting point
# center point of screen
# start_x, start_y = pyautogui.size()[0] // 2, pyautogui.size()[1] // 2
# wherever the mouse happens to be
start_x, start_y = pyautogui.position()
pyautogui.moveTo(start_x, start_y)
radius = 0
angle = 0
while radius < 180:
x = start_x + int(radius * math.cos(math.radians(angle)))
y = start_y + int(radius * math.sin(math.radians(angle)))
pyautogui.moveTo(x, y)
angle += 5
radius += 4
time.sleep(0.01)
while radius > 0:
x = start_x + int(radius * math.cos(math.radians(angle)))
y = start_y + int(radius * math.sin(math.radians(angle)))
pyautogui.moveTo(x, y)
angle -= 5
radius -= 4
time.sleep(0.05)
pyautogui.click()
time.sleep(180)
def fibonacci_spiral():
while True:
# Get the current mouse cursor position
start_x, start_y = pyautogui.position()
# Define the initial Fibonacci numbers
fib_prev = 1
fib_curr = 1
# Initial angle and distance from the starting point
angle = 0
distance = 0
# Spiral outwards following the Fibonacci sequence
while distance < 100:
# Calculate the new coordinates based on the Fibonacci spiral equation
x = start_x + int(fib_curr * math.cos(math.radians(angle)))
y = start_y + int(fib_curr * math.sin(math.radians(angle)))
# Move the mouse to the new coordinates
pyautogui.moveTo(x, y)
# Update Fibonacci numbers
fib_next = fib_curr + fib_prev
fib_prev = fib_curr
fib_curr = fib_next
# Increase the angle
angle += 10 # Adjust the step size
# Calculate the distance from the starting point
distance = math.sqrt((x - start_x)**2 + (y - start_y)**2)
# Pause briefly to make the movement visible
time.sleep(0.001)
pyautogui.click()
time.sleep(180)
# Usage
# Uncomment one of the below spirals
#standard_spiral()
fibonacci_spiral()
# Shell Prompt
# python mouse_move3.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment