here is what I have so far but it's not human enough, How can I get the speed to vary along the path? also any other suggestions are apprettiated!
Code:
import pyautogui
import random
def move_mouse_randomly(box_x, box_y, box_width, box_height, duration=1.0, pause=0.0):
# Calculate the center of the box
center_x = box_x + box_width / 2
center_y = box_y + box_height / 2
# Generate random x and y coordinates within the box
x = random.uniform(box_x, box_x + box_width)
y = random.uniform(box_y, box_y + box_height)
# Calculate the distance from the center
distance_from_center = ((x - center_x) ** 2 + (y - center_y) ** 2) ** 0.5
# Use a Gaussian function to weight the coordinates towards the center
weight = random.gauss(0, distance_from_center / 3)
# Get the current mouse position
current_x, current_y = pyautogui.position()
# Calculate the distance to move the mouse
distance_x = x + weight - current_x
distance_y = y + weight - current_y
# Calculate the number of steps to take
steps = int(duration * 10) # 10 steps per second
# Calculate the delay between steps
delay = duration / steps
# Move the mouse in a straight line
for i in range(steps):
pyautogui.moveRel(distance_x / steps, distance_y / steps)
pyautogui.pause(delay)
# Pause before returning the cursor to its original position
pyautogui.pause(pause)
This function takes four required arguments: the x and y coordinates of the top-left corner of the box, and the width and height of the box. It also has two optional arguments:
duration: the time, in seconds, to take to move the mouse. The default value is 1.0 seconds.
pause: the time, in seconds, to pause after moving the mouse. The default value is 0.0 seconds.
To use this function, you can call it with the coordinates and dimensions of the box:
Code:
move_mouse_randomly(100, 100, 200, 200)
This will move the mouse slowly and smoothly, in an imperfect straight line, to a random spot within the box with the top-left corner at (100, 100) and dimensions of 200x200 pixels, with a bias towards the center of the box.
You can also specify the duration and pause arguments to customize the movement:
Code:
move_mouse_randomly(100, 100, 200, 200, duration=0.5, pause=1.0)