### Install OxyMouse Source: https://github.com/oxylabs/oxymouse/blob/master/README.md Install the library using pip. This is the first step before using any of its functionalities. ```bash pip install oxymouse ``` -------------------------------- ### Integrate OxyMouse with Playwright Source: https://context7.com/oxylabs/oxymouse/llms.txt Demonstrates integrating OxyMouse with Playwright for automated browser interactions. This example shows moving the mouse to a specific location and simulating a scroll action. Ensure `playwright` and `oxymouse` are installed. ```python import asyncio import random from oxymouse import OxyMouse from playwright.async_api import async_playwright async def main(): mouse = OxyMouse(algorithm="gaussian") async with async_playwright() as p: browser = await p.chromium.launch(headless=False) page = await browser.new_page() await page.goto("https://example.com", wait_until="domcontentloaded") # Move to a known button location movements = mouse.generate_coordinates(from_x=0, from_y=0, to_x=640, to_y=360) for x, y in movements: await page.mouse.move(x, y) await asyncio.sleep(random.uniform(0.001, 0.003)) await page.mouse.click(640, 360) # Simulate a scroll scroll_coords = mouse.generate_scroll_coordinates(start_y=0, end_y=2000) for _, y in scroll_coords: await page.mouse.wheel(0, y) await asyncio.sleep(0.01) await browser.close() asyncio.run(main()) ``` -------------------------------- ### Integrate OxyMouse with Selenium Source: https://context7.com/oxylabs/oxymouse/llms.txt Shows how to integrate OxyMouse with Selenium for mouse control in web automation. This example moves the mouse to a specific element and simulates random viewport movement. Requires `selenium` and `oxymouse` to be installed. ```python import random import time from oxymouse import OxyMouse from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC mouse = OxyMouse(algorithm="perlin") driver = webdriver.Chrome() try: driver.get("https://example.com") WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.TAG_NAME, "body"))) # Move to a button at (800, 400) movements = mouse.generate_coordinates(from_x=0, from_y=0, to_x=800, to_y=400) actions = ActionChains(driver) for x, y in movements: actions.move_by_offset(x - (movements[movements.index((x,y))-1][0] if movements.index((x,y)) > 0 else 0), y - (movements[movements.index((x,y))-1][1] if movements.index((x,y)) > 0 else 0)) actions.pause(random.uniform(0.001, 0.003)) actions.perform() # Simulate random viewport movement idle = mouse.generate_random_coordinates(viewport_width=1280, viewport_height=720) print(f"Idle path steps: {len(idle)}") finally: driver.quit() ``` -------------------------------- ### Generate Point-to-Point Mouse Movement Source: https://context7.com/oxylabs/oxymouse/llms.txt Generates a smooth path of (x, y) coordinates from a start to a target position. Ideal for moving the cursor to specific UI elements. The number of steps is approximately 60 per second. ```python 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) print(f"Total steps: {len(movements)}") # Total steps: 60 (≈1 second at 60 fps) print(f"First point : {movements[0]}") # (400, 500) print(f"Last point : {movements[-1]}") # (1000, 1200) # Replay each step against Playwright # for x, y in movements: # await page.mouse.move(x, y) ``` -------------------------------- ### Generate Scroll Path Source: https://context7.com/oxylabs/oxymouse/llms.txt Generates a sequence of (0, y) coordinate tuples for scroll movements from a start Y to an end Y. The x-coordinate remains 0. ```python from oxymouse import OxyMouse mouse = OxyMouse(algorithm="perlin") # Scroll from y=0 down to y=3000 scroll_coords = mouse.generate_scroll_coordinates(start_y=0, end_y=3000) print(f"Scroll steps : {len(scroll_coords)}") print(f"Start y : {scroll_coords[0][1]}") # near 0 print(f"End y : {scroll_coords[-1][1]}") # 3000 # Replay scroll steps in Selenium # actions = ActionChains(driver) # for _, y in scroll_coords: # actions.scroll_by_amount(0, y) # actions.perform() ``` -------------------------------- ### generate_coordinates Source: https://context7.com/oxylabs/oxymouse/llms.txt Generates a smooth, human-like path of (x, y) coordinate tuples from a starting position to a target position. Ideal for moving the cursor to a specific UI element. ```APIDOC ## `generate_coordinates` — Point-to-Point Mouse Movement Generates a smooth, human-like path of `(x, y)` coordinate tuples from a starting position to a target position. Ideal for moving the cursor to a specific UI element such as a button or link. ```python 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) print(f"Total steps: {len(movements)}") # Total steps: 60 (≈1 second at 60 fps) print(f"First point : {movements[0]}") # (400, 500) print(f"Last point : {movements[-1]}") # (1000, 1200) # Replay each step against Playwright # for x, y in movements: # await page.mouse.move(x, y) ``` ``` -------------------------------- ### Generate Mouse Movements Between Two Points Source: https://github.com/oxylabs/oxymouse/blob/master/README.md Generate a sequence of mouse movements from a starting point (from_x, from_y) to an ending point (to_x, to_y). This is ideal for simulating clicks on specific elements. ```python from oxymouse import OxyMouse mouse = OxyMouse(algorithm="bezier") movements = mouse.generate_coordinates(from_x=400, from_y=500, to_x=1000, to_y=1200) ``` -------------------------------- ### Generate Gaussian Mouse Movements Source: https://context7.com/oxylabs/oxymouse/llms.txt Generates mouse paths using a Gaussian random walk combined with Bézier interpolation. Configure `smoothness` for path smoothness and `randomness` for deviation. The generated movements precisely match the start and end points. ```python from oxymouse.algorithms.gaussian_mouse.gaussian_mouse import GaussianMouse movements = GaussianMouse.generate_gaussian_mouse_movements( start_x=100, start_y=100, end_x=900, end_y=700, duration=1.0, smoothness=3.0, # higher = smoother path randomness=1.5, # higher = more deviation ) print(f"Steps : {len(movements)}") print(f"Start : {movements[0]}") # (100, 100) — exact print(f"End : {movements[-1]}") # (900, 700) — exact ``` -------------------------------- ### Generate Mouse Movements for Scrolling Source: https://github.com/oxylabs/oxymouse/blob/master/README.md Generate coordinates specifically for simulating scroll actions. This method does not require specific start or end points. ```python from oxymouse import OxyMouse mouse = OxyMouse(algorithm="bezier") movements = mouse.generate_scroll_coordinates() ``` -------------------------------- ### Generate Perlin Noise Mouse Movements Source: https://context7.com/oxylabs/oxymouse/llms.txt Generates organic, flowing mouse movements using Perlin noise. The `generate_perlin_mouse_movements` function produces raw, time-based noise. For coordinate-based generation, use the unified `OxyMouse` API which auto-scales to the specified start and end bounds. ```python from oxymouse.algorithms.perlin_mouse.perlin_mouse import PerlinMouse # Direct noise generation (runs in real time) raw = PerlinMouse.generate_perlin_mouse_movements( duration=1.0, octaves=6, persistence=0.5, lacunarity=2.0, seed=42, # fixed seed for reproducibility ) print(f"Raw steps : {len(raw)}") # Via unified API — auto-scaled to start/end coordinates from oxymouse import OxyMouse mouse = OxyMouse(algorithm="perlin") movements = mouse.generate_coordinates(from_x=0, from_y=0, to_x=1200, to_y=800) print(f"Scaled steps : {len(movements)}") print(f"End point : {movements[-1]}") ``` -------------------------------- ### OxyMouse Class Instantiation Source: https://context7.com/oxylabs/oxymouse/llms.txt The OxyMouse class is the main entry point. It can be instantiated with different movement algorithms. An invalid algorithm name will raise a ValueError. ```APIDOC ## OxyMouse Class — Instantiation The `OxyMouse` class is the single entry point for the library. It accepts an `algorithm` string at construction time and raises `ValueError` for unrecognized algorithm names. Valid values are `"bezier"`, `"gaussian"`, `"perlin"`, and `"oxy"`. ```python from oxymouse import OxyMouse # Instantiate with each supported algorithm bezier_mouse = OxyMouse(algorithm="bezier") gausian_mouse = OxyMouse(algorithm="gaussian") perlin_mouse = OxyMouse(algorithm="perlin") oxy_mouse = OxyMouse(algorithm="oxy") # Invalid algorithm raises ValueError try: bad = OxyMouse(algorithm="unknown") except ValueError as e: print(e) # "Invalid algorithm" ``` ``` -------------------------------- ### Visualize Mouse Movement Algorithms with CLI Source: https://context7.com/oxylabs/oxymouse/llms.txt Use the visualize.py CLI tool to preview different mouse movement algorithms and coordinate generation functions. Supported shorthands include gc (generate_coordinates), grc (generate_random_coordinates), and gsc (generate_scroll_coordinates). ```bash # Syntax: python3 visualize.py # Shorthands: gc=generate_coordinates, grc=generate_random_coordinates, gsc=generate_scroll_coordinates python3 visualize.py bezier gc # Bézier point-to-point path python3 visualize.py gaussian grc # Gaussian random viewport movement python3 visualize.py perlin gsc # Perlin scroll coordinates python3 visualize.py oxy gc # OxyMouse multi-phase path ``` -------------------------------- ### Test Generated Mouse Movements with CLI Source: https://github.com/oxylabs/oxymouse/blob/master/README.md Use the command-line interface to visualize generated mouse movements with a specific algorithm and function. This helps in testing and debugging movement patterns. ```bash python3 visualize.py bezier gc ``` -------------------------------- ### OxyMouse Class Instantiation Source: https://context7.com/oxylabs/oxymouse/llms.txt Instantiate the OxyMouse class with supported algorithms. An invalid algorithm name will raise a ValueError. ```python from oxymouse import OxyMouse # Instantiate with each supported algorithm besier_mouse = OxyMouse(algorithm="bezier") gaussian_mouse = OxyMouse(algorithm="gaussian") perlin_mouse = OxyMouse(algorithm="perlin") oxy_mouse = OxyMouse(algorithm="oxy") # Invalid algorithm raises ValueError try: bad = OxyMouse(algorithm="unknown") except ValueError as e: print(e) # "Invalid algorithm" ``` -------------------------------- ### Generate Realistic Multi-Phase Mouse Movements (Oxy Algorithm) Source: https://context7.com/oxylabs/oxymouse/llms.txt Simulates physiologically realistic mouse motion with distinct acceleration, correction, and deceleration phases. Use `OxyAlgorithm._generate_movements` for direct access with custom parameters or the unified `OxyMouse` API for auto-scaled coordinate generation. ```python from oxymouse.algorithms.oxy.oxy_mouse import OxyMouse as OxyAlgorithm # Direct access with custom parameters movements = OxyAlgorithm._generate_movements( duration=1.0, octaves=6, persistence=0.5, lacunarity=2.0, seed=12345, max_velocity=8000.0, ) print(f"Steps: {len(movements)}") # Via unified API from oxymouse import OxyMouse mouse = OxyMouse(algorithm="oxy") movements = mouse.generate_coordinates(from_x=50, from_y=50, to_x=1500, to_y=900) print(f"First: {movements[0]}, Last: {movements[-1]}") ``` -------------------------------- ### BezierAlgorithm.generate_bezier_mouse_movements Source: https://context7.com/oxylabs/oxymouse/llms.txt Directly uses the Bezier algorithm to generate mouse paths using Bézier curves with configurable control points, duration, complexity, and randomness. Produces smooth, arc-like trajectories. ```APIDOC ## Bezier Algorithm — Bézier Curve Movements Generates mouse paths using Bézier curves with configurable control points, duration, complexity, and randomness. Produces smooth, arc-like trajectories — ideal for clicking buttons. ```python from oxymouse.algorithms.bezier_mouse.bezier_mouse import BezierMouse # Direct algorithm access for fine-grained control movements = BezierMouse.generate_bezier_mouse_movements( start_x=0, start_y=0, end_x=800, end_y=600, duration=1.5, # 1.5 seconds → ~90 steps at 60 fps complexity=6, # 6 control points (min 4) randomness=0.5, # moderate path deviation ) print(f"Steps : {len(movements)}") print(f"Start : {movements[0]}") print(f"End : {movements[-1]}") # Steps: 90 # Start: (0, 0) # End: (800, 600) ``` ``` -------------------------------- ### Bezier Algorithm Direct Access Source: https://context7.com/oxylabs/oxymouse/llms.txt Directly use the BezierMouse algorithm for fine-grained control over mouse path generation using Bézier curves. Allows configuration of control points, duration, complexity, and randomness. ```python from oxymouse.algorithms.bezier_mouse.bezier_mouse import BezierMouse # Direct algorithm access for fine-grained control movements = BezierMouse.generate_bezier_mouse_movements( start_x=0, start_y=0, end_x=800, end_y=600, duration=1.5, # 1.5 seconds → ~90 steps at 60 fps complexity=6, # 6 control points (min 4) randomness=0.5, # moderate path deviation ) print(f"Steps : {len(movements)}") print(f"Start : {movements[0]}") print(f"End : {movements[-1]}") # Steps: 90 # Start: (0, 0) # End: (800, 600) ``` -------------------------------- ### Generate Random Mouse Movements Source: https://github.com/oxylabs/oxymouse/blob/master/README.md Initialize OxyMouse with a chosen algorithm and generate random coordinates within the specified viewport dimensions. Useful for simulating general cursor activity. ```python from oxymouse import OxyMouse mouse = OxyMouse(algorithm="bezier") movements = mouse.generate_random_coordinates(viewport_width=1920, viewport_height=1080) ``` -------------------------------- ### Function Name Mapping for CLI Source: https://github.com/oxylabs/oxymouse/blob/master/README.md A dictionary mapping short command-line aliases to their corresponding function names in the OxyMouse library. This is used internally by the visualization script. ```python function_names_to_function_map = { "gc": "generate_coordinates", "grc": "generate_random_coordinates", "gsc": "generate_scroll_coordinates", } ``` -------------------------------- ### Generate Random Viewport Movement Source: https://context7.com/oxylabs/oxymouse/llms.txt Generates a movement path from (0, 0) to a random destination within specified viewport dimensions. Useful for simulating idle cursor activity. The default viewport is 1920x1080. ```python from oxymouse import OxyMouse mouse = OxyMouse(algorithm="gaussian") # Generate random movement within a 1920×1080 viewport (default) movements = mouse.generate_random_coordinates(viewport_width=1920, viewport_height=1080) print(f"Steps generated : {len(movements)}") print(f"Destination : {movements[-1]}") # Destination: (e.g., (1432, 876)) — random each call # Compact viewport example movements_small = mouse.generate_random_coordinates(viewport_width=1280, viewport_height=720) print(f"First: {movements_small[0]}, Last: {movements_small[-1]}") ``` -------------------------------- ### generate_random_coordinates Source: https://context7.com/oxylabs/oxymouse/llms.txt Generates a movement path from the origin (0, 0) to a random destination within the supplied viewport dimensions. Useful for simulating idle, exploratory cursor activity. ```APIDOC ## `generate_random_coordinates` — Random Viewport Movement Generates a movement path from the origin `(0, 0)` to a random destination within the supplied viewport dimensions. Useful for simulating idle, exploratory cursor activity on a page. ```python from oxymouse import OxyMouse mouse = OxyMouse(algorithm="gaussian") # Generate random movement within a 1920×1080 viewport (default) movements = mouse.generate_random_coordinates(viewport_width=1920, viewport_height=1080) print(f"Steps generated : {len(movements)}") print(f"Destination : {movements[-1]}") # Destination: (e.g., (1432, 876)) — random each call # Compact viewport example movements_small = mouse.generate_random_coordinates(viewport_width=1280, viewport_height=720) print(f"First: {movements_small[0]}, Last: {movements_small[-1]}") ``` ``` -------------------------------- ### generate_scroll_coordinates Source: https://context7.com/oxylabs/oxymouse/llms.txt Generates a sequence of (0, y) coordinate tuples that describe a scroll movement from start_y to end_y. The x-coordinate is always 0. ```APIDOC ## `generate_scroll_coordinates` — Scroll Path Generation Generates a sequence of `(0, y)` coordinate tuples that describe a scroll movement from `start_y` to `end_y`. The x-coordinate is always `0`; only the y-axis is animated. ```python from oxymouse import OxyMouse mouse = OxyMouse(algorithm="perlin") # Scroll from y=0 down to y=3000 scroll_coords = mouse.generate_scroll_coordinates(start_y=0, end_y=3000) print(f"Scroll steps : {len(scroll_coords)}") print(f"Start y : {scroll_coords[0][1]}") # near 0 print(f"End y : {scroll_coords[-1][1]}") # 3000 # Replay scroll steps in Selenium # actions = ActionChains(driver) # for _, y in scroll_coords: # actions.scroll_by_amount(0, y) # actions.perform() ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.