Path Generator¶
A Python library for generating human-like mouse movement paths using PD (Proportional-Derivative) control.
Features¶
- Human-like trajectories - Curved paths with natural velocity profiles
- Fitts's Law compliance - Automatic deceleration near targets
- Configurable behavior - Tune speed, curvature, noise, and more
- Resolution independent - Works across different screen sizes
- Overshoot simulation - Optional target overshoot and correction
Installation¶
Quick Start¶
from pathgenerator import PDPathGenerator
# Create generator
gen = PDPathGenerator()
# gen = PDPathGenerator('params.json') to load params from a json file
# Define points
start_x, start_y = 100, 200
end_x, end_y = 900, 1000
# Generate a path
path, prog_list, steps, params = gen.generate_path(
start_x=start_x, start_y=start_y,
end_x=end_x, end_y=end_y,
offset_x=0, offset_y=0 # Optional offset if you target a relative area
)
# path is a numpy array of (x, y) coordinates
for x, y in path:
print(f"Move to ({x:.1f}, {y:.1f})")
Tuning Workflow (Server + JSON)¶
The easiest way to find realistic parameters is to use the interactive playground.
(Requires: pip install pathgenerator[server])
- Launch the server:
- Tune settings at
http://127.0.0.1:8001. - Download JSON: Click "Export Preset" to save your settings as
human_relaxed.json. - Load in Python:
Executing Paths (Windows Only)¶
The PathEmulator class includes a helper get_position() to simplify generating paths from your current mouse location.
from pathgenerator import PDPathGenerator, PathEmulator
# Requires: pip install pathgenerator[windows]
emulator = PathEmulator()
gen = PDPathGenerator()
# 1. Get current mouse position
start_x, start_y = emulator.get_position()
# 2. Generate path to target (e.g., 500, 500)
# calculate offset if you are targeting a window relative to screen 0,0
path, *_ = gen.generate_path(start_x, start_y, 500, 500)
# 3. Move the mouse (optional delay to control playback speed)
emulator.execute_path(path, delay_between_points=0.001)
How It Works¶
The generator uses a unit-frame approach:
- Transform the problem so start=(0,0) and target=(1,0)
- Simulate movement with PD control for correction
- Add human-like noise and velocity profiles
- Transform back to screen coordinates
See the Algorithm Guide for a detailed explanation.
Next Steps¶
- Algorithm Guide - Understand how path generation works
- Basic Usage - Common usage patterns
- Tuning Parameters - Fine-tune path characteristics
- API Reference - Full API documentation