OxyMouse

repository·master·Indexed 43 days ago

https://github.com/oxylabs/oxymouse

A Python library for generating realistic synthetic mouse movement coordinate sequences using mathematical algorithms such as Bezier curves, Gaussian distribution, Perlin noise, and a custom oxy algorithm. Version 1.1.1 provides methods to generate coordinates between two points, random movements within a viewport, and scroll coordinates for use with browser automation tools.

Tokens
1.5K
Snippets
11
Records
12
Agent score
53%

What's inside OxyMouse

  1. Supported movement algorithms

    master

    OxyMouse supports several algorithms to control the nature of the mouse movement:

    • bezier: Uses Bezier curves. Ideal for smooth movements when clicking buttons.
    • gaussian: Uses Gaussian distribution. Best for simulating human-like jitter and movement.
    • perlin: Uses Perlin noise. Also used for simulating human-like movement.
    • oxy: A custom OxyMouse algorithm.
  2. Visualize generated mouse movements

    master

    You can visually test and inspect the generated movements using the visualize.py CLI tool. The tool maps short aliases to the library's methods.

    Method Aliases:

    • gc: generate_coordinates
    • grc: generate_random_coordinates
    • gsc: generate_scroll_coordinates

    Example Command: To visualize movements generated by the bezier algorithm using the generate_coordinates method, run:

    python3 visualize.py bezier gc
  3. Use OxyMouse to generate mouse movements

    master

    To use OxyMouse, instantiate the OxyMouse class and specify an algorithm. You can then call methods to generate different types of coordinate sequences.

    from oxymouse import OxyMouse
    
    # Initialize with a specific algorithm
    mouse = OxyMouse(algorithm="bezier")
    
    # Generate random movements within a viewport
    movements = mouse.generate_random_coordinates(viewport_width=1920, viewport_height=1080)
  4. Generate coordinates between two points

    master

    Use the generate_coordinates method to generate a path from a specific starting point (from_x, from_y) to a target destination (to_x, to_y). This is useful for simulating a move to a specific UI element like a button.

    from oxymouse import OxyMouse
    
    mouse = OxyMouse(algorithm="bezier")
    # Move from (400, 500) to (1000, 1200)
    movements = mouse.generate_coordinates(from_x=400, from_y=500, to_x=1000, to_y=1200)
  5. Generate scroll coordinates

    master

    Use the generate_scroll_coordinates method to generate a sequence of coordinates intended for simulating scrolling behavior.

    from oxymouse import OxyMouse
    
    mouse = OxyMouse(algorithm="bezier")
    movements = mouse.generate_scroll_coordinates()
  6. Generate random coordinates within a viewport

    master

    Use the generate_random_coordinates method to create a sequence of movements that stay within the bounds of a specified viewport width and height.

    from oxymouse import OxyMouse
    
    mouse = OxyMouse(algorithm="bezier")
    movements = mouse.generate_random_coordinates(viewport_width=1920, viewport_height=1080)
  7. Initialize OxyMouse with a specific algorithm

    master

    To use OxyMouse, instantiate the OxyMouse class by passing the name of the desired algorithm as a string. The class uses an internal registry to resolve the algorithm. If an unsupported algorithm name is provided, it will raise a ValueError with the message "Invalid algorithm".

    from oxymouse.oxymouse import OxyMouse
    
    # Initialize with a specific algorithm name
    mouse_generator = OxyMouse(algorithm="Bezier")
  8. Available mouse movement algorithms in OxyMouse

    master

    OxyMouse provides several algorithms for generating mouse movement patterns. You can access these algorithms via the mouses dictionary, which maps algorithm names to their respective class instances. The supported algorithms are:

    • perlin: Uses Perlin noise for movement.
    • bezier: Uses Bezier curves for movement.
    • gaussian: Uses Gaussian distribution for movement.
    • oxy: Uses the proprietary OxyMouse algorithm.
    from oxymouse.config import mouses
    
    # Accessing a specific algorithm instance
    perlin_algorithm = mouses["perlin"]
    bezier_algorithm = mouses["bezier"]
    gaussian_algorithm = mouses["gaussian"]
    oxy_algorithm = mouses["oxy"]
  9. Generate random mouse movement coordinates

    master

    Use generate_random_coordinates to generate a sequence of coordinates within a specified viewport size. This is useful for simulating non-linear, randomized mouse activity.

    # Generates random coordinates within a 1920x1080 viewport
    random_coords = mouse_generator.generate_random_coordinates(viewport_width=1920, viewport_height=1080)
  10. Generate mouse movement coordinates

    master

    Use generate_coordinates to create a path of (x, y) tuples moving from a starting point to a destination point using the initialized algorithm.

    # Generates coordinates from (0, 0) to (1000, 1000)
    coordinates = mouse_generator.generate_coordinates(from_x=0, from_y=0, to_x=1000, to_y=1000)