A Python package for smooth mouse movement using a C library.
Project description
Mouse Anywhere Library
Overview
Mouse Anywhere is a Python library powered by a DLL for dynamic mouse control on Windows. This library allows you to:
- Move the cursor to any absolute position on the screen.
- Simulate mouse clicks (left, right, middle).
- Perform smooth cursor movements with customizable easing types.
- Dynamically update configuration settings.
- Log mouse interactions at different levels (error, info, debug).
This package is suitable for applications requiring precise mouse control, such as automated testing, custom accessibility solutions, or macro creation.
====================================
Features
- Cursor Control: Move the cursor to specified screen coordinates.
- Mouse Clicks: Simulate mouse clicks with configurable hold times.
- Smooth Movements: Enable smooth cursor movements with easing types like linear, quadratic, sinusoidal, cubic, and exponential.
- Presets: Apply predefined configurations for fast, smooth, or default behavior.
- Logging: Monitor mouse interactions with adjustable log levels.
====================================
Installation
Install the library using pip:
pip install mouse-anywhere
====================================
Getting Started
Initialization
To use the library, initialize it first:
from mouse_anywhere import initialize, mouse_shutdown
# Initialize the library
initialize()
# Shutdown the library (when done)
mouse_shutdown()
Example Usage
Moving the Cursor
from mouse_anywhere import set_cursor_abs
# Move the cursor to screen coordinates (100, 200)
set_cursor_abs(100, 200)
Simulating Mouse Clicks
from mouse_anywhere import click
# Perform a left mouse click
click(1)
# Perform a right mouse click
click(2)
Smooth Movement
from mouse_anywhere import hold_and_move
# Hold the left mouse button and move to (300, 400) over 2 seconds
hold_and_move(300, 400, 1, 2000)
Applying Presets
from mouse_anywhere import apply_preset
# Apply the "smooth" preset
apply_preset(3)
Custom Configurations
from mouse_anywhere import set_config
# Set custom configurations
set_config(
strength=70, # Strength (1-100)
hold_time_ms=500, # Hold time in milliseconds
mouse_speed=10, # Movement speed in ms per step
easing_type=2, # Easing type (1-5)
smooth_movement=True
)
Adjust Logging Level
from mouse_anywhere import set_logging_level
# Set logging to debug level
set_logging_level(3)
====================================
Configuration Details
Easing Types
Easing types control the smoothness of cursor movement:
- Linear: 1
- Quadratic: 2
- Sinusoidal: 3
- Cubic: 4
- Exponential: 5
Presets
Presets offer predefined configurations:
- Default: Strength=50, Hold Time=300ms, Speed=5, Easing=Linear
- Fast: Strength=80, Hold Time=100ms, Speed=2, Easing=Exponential
- Smooth: Strength=30, Hold Time=500ms, Speed=10, Easing=Sinusoidal
Logging Levels
Control the verbosity of logs:
- None: 0 (No logging)
- Error: 1 (Log errors only)
- Info: 2 (Log informational messages)
- Debug: 3 (Log detailed debug messages)
====================================
DLL Integration
The library uses mouse_anywhere2.dll for low-level mouse control. Ensure the DLL is packaged with the library and accessible in the Python module directory.
If you encounter issues:
- Verify the DLL is present in the installed package directory.
- Confirm your system is running a compatible version of Windows.
DLL Methods
Below are the exported methods from the DLL:
- initialize(): Initializes the mouse library.
- mouse_shutdown(): Shuts down the library and cleans up resources.
- set_cursor_abs(x, y): Moves the cursor to absolute screen coordinates.
- click(button): Simulates a mouse click. Acceptable values for
button:- 1: Left click
- 2: Right click
- 3: Middle click
- hold_and_move(x, y, button, duration_ms): Holds the specified button and moves the cursor to the specified coordinates over the given duration.
- set_mouse_speed(speed): Sets the speed for cursor movement. Speed must be greater than 0.
- set_config(strength, hold_time_ms, mouse_speed, easing_type, smooth_movement): Dynamically updates the library configuration with detailed parameters.
- apply_preset(preset_type): Applies predefined configurations (1: Default, 2: Fast, 3: Smooth).
- set_logging_level(level): Adjusts the logging verbosity (0: None, 1: Error, 2: Info, 3: Debug).
====================================
Troubleshooting
Common Errors
- FileNotFoundError: Ensure the DLL is correctly installed and accessible.
- ValueError: Check the input parameters for invalid values.
Debugging Steps
- Enable debug logging with
set_logging_level(3). - Check the log file (
mouse_movement.log) for detailed information. - Use the
initialize()method to verify proper setup.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mouse-anywhere-0.2.5.tar.gz.
File metadata
- Download URL: mouse-anywhere-0.2.5.tar.gz
- Upload date:
- Size: 110.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24006d4d32e5e913aa624001bac0d2ac4712dd7dffefe04bcd2cdf1e70e27e44
|
|
| MD5 |
155122e241f543756b1575a2705a263a
|
|
| BLAKE2b-256 |
4ade316a9ddfb45d700d704976592a3c74061ae657e85fde83f0a80258306c31
|
File details
Details for the file mouse_anywhere-0.2.5-py3-none-any.whl.
File metadata
- Download URL: mouse_anywhere-0.2.5-py3-none-any.whl
- Upload date:
- Size: 108.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d985db138c02247edc993b1f9c6e5bf31ff92c836ec02bfcc7c1fa0304cc95d1
|
|
| MD5 |
c63c7705d79a4a1c0fecdafd972a3997
|
|
| BLAKE2b-256 |
a17c38d07cc081d6130ac5ac3ef752c26ad61db4269d5918b80891fd0983ef16
|