mouse

raw JSON →
0.7.1 verified Mon Apr 27 auth: no python

Library to hook and simulate mouse events on Windows and Linux. Current version 0.7.1. Maintained infrequently, with rare releases.

pip install mouse
error AttributeError: module 'mouse' has no attribute 'record'
cause Older version (<0.6.0) missing record/playback. Or pip installed wrong package.
fix
Upgrade: pip install --upgrade mouse
error OSError: [Errno 13] Permission denied: '/dev/input/mice'
cause User lacks permission to read input devices on Linux.
fix
Add user to 'input' group: sudo usermod -a -G input $USER then logout/reboot, or run script with sudo.
error ImportError: No module named 'mouse'
cause Package not installed or virtual environment not activated.
fix
pip install mouse
gotcha mouse.record() blocks until user presses right mouse button (by default). To stop recording programmatically, you must call mouse.unhook_all() from a separate thread or use hook().
fix Use mouse.hook() to capture events non-blockingly, or run record() in another thread and call mouse.unhook_all() to stop.
gotcha On Linux, mouse requires X server and may need sudo for access to /dev/input/mice. Without proper permissions, hooks silently fail or no events fire.
fix Run as root or add user to 'input' group. Check /dev/input/mice access.
deprecated mouse.is_pressed() is not implemented; checking mouse button state is not supported. Only hooks and events are available.
fix Use on_click callback to detect button presses instead.

Move mouse, click, listen to clicks, record and replay events.

import mouse
mouse.move(200, 300)
mouse.click('left')
mouse.on_click(lambda: print('clicked'))
# Record and play events
recorded = mouse.record()
mouse.play(recorded)