• Stars
    star
    861
  • Rank 50,803 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hook and simulate global mouse events in pure Python

mouse

Take full control of your mouse with this small Python library. Hook global events, register hotkeys, simulate mouse movement and clicks, and much more.

Huge thanks to Kirill Pavlov for donating the package name. If you are looking for the Cheddargetter.com client implementation, pip install mouse==0.5.0.

Features

  • Global event hook on all mice devices (captures events regardless of focus).
  • Listen and sends mouse events.
  • Works with Windows and Linux (requires sudo).
  • Works with MacOS (requires granting accessibility permissions to terminal/python in System Preferences -> Security & Privacy)
  • Pure Python, no C modules to be compiled.
  • Zero dependencies on Windows and Linux. Trivial to install and deploy, just copy the files.
  • Python 2 and 3.
  • Includes high level API (e.g. record and play.
  • Events automatically captured in separate thread, doesn't block main program.
  • Tested and documented.

This program makes no attempt to hide itself, so don't use it for keyloggers.

Usage

Install the PyPI package:

$ sudo pip install mouse

or clone the repository (no installation required, source files are sufficient):

$ git clone https://github.com/boppreh/mouse

Then check the API docs to see what features are available.

Known limitations:

  • Events generated under Windows don't report device id (event.device == None). #21
  • To avoid depending on X the Linux parts reads raw device files (/dev/input/input*) but this requires root.
  • Other applications, such as some games, may register hooks that swallow all key events. In this case mouse will be unable to report events.

API

Table of Contents

ButtonEvent(event_type, button, time)

Alias for field number 1

Return number of occurrences of value.

Alias for field number 0

Return first index of value.

Raises ValueError if the value is not present.

Alias for field number 2

= 'double'
= 'down'
= 'left'
= 'middle'

MoveEvent(x, y, time)

Return number of occurrences of value.

Return first index of value.

Raises ValueError if the value is not present.

Alias for field number 2

Alias for field number 0

Alias for field number 1

= 'right'
= 'up'

WheelEvent(delta, time)

Return number of occurrences of value.

Alias for field number 0

Return first index of value.

Raises ValueError if the value is not present.

Alias for field number 1

= 'x'
= 'x2'
= '0.7.1'

[source]

Returns True if the given button is currently pressed.

[source]

Presses the given button (but doesn't release).

[source]

Releases the given button.

[source]

Sends a click with the given button.

[source]

Sends a double click with the given button.

[source]

Sends a right click with the given button.

[source]

Scrolls the wheel delta clicks. Sign indicates direction.

[source]

Moves the mouse. If absolute, to position (x, y), otherwise move relative to the current position. If duration is non-zero, animates the movement. The fps of the animation is determined by 'steps_per_second', default is 120.

[source]

Holds the left mouse button, moving from start to end position, then releases. absolute and duration are parameters regarding the mouse movement.

[source]

Invokes callback with args when the specified event happens.

[source]

Invokes callback with args when the left button is clicked.

[source]

Invokes callback with args when the left button is double clicked.

[source]

Invokes callback with args when the right button is clicked.

[source]

Invokes callback with args when the middle button is clicked.

[source]

Blocks program execution until the given button performs an event.

[source]

Returns the (x, y) mouse position.

[source]

Installs a global listener on all available mouses, invoking callback each time it is moved, a key status changes or the wheel is spun. A mouse event is passed as argument, with type either mouse.ButtonEvent, mouse.WheelEvent or mouse.MoveEvent.

Returns the given callback for easier development.

[source]

Removes a previously installed hook.

[source]

Removes all hooks registered by this application. Note this may include hooks installed by high level functions, such as record.

[source]

Records all mouse events until the user presses the given button. Then returns the list of events recorded. Pairs well with play(events).

Note: this is a blocking function. Note: for more details on the mouse hook and events see hook.

[source]

Plays a sequence of recorded events, maintaining the relative time intervals. If speed_factor is <= 0 then the actions are replayed as fast as the OS allows. Pairs well with record().

The parameters include_* define if events of that type should be included in the replay or ignored.

More Repositories

1

keyboard

Hook and simulate global keyboard events on Windows and Linux.
Python
3,683
star
2

steamgrid

Downloads images to fill your Steam grid view
Go
637
star
3

maze

Simple maze generator in Python
Python
62
star
4

bayesian

Utility for Bayesian reasoning
Python
37
star
5

server-sent-events

Python library for Server-Sent-Events
Python
36
star
6

minetesting

Client and mod for the Minetest game
Logos
15
star
7

hello_tls

Send TLS client hello in pure Python, for enumerating supported server cipher suites and protocols
Python
15
star
8

replace_me

Modify your own source code with this piece of Python black magic
Python
14
star
9

simplecrypto

Simple cryptographic library for hashing and encrypting
Python
12
star
10

gomeet

Go server to punch NAT holes
Go
11
star
11

carlo

Interactively plot streaming sequences of numbers
Python
9
star
12

structured-editor

Structured editor for general purpose programming languages
Python
8
star
13

gifencoder

The missing method gif.Encode in Go's library
Go
8
star
14

marktex

Markdown to Latex for thesis, reports, and presentations
Python
8
star
15

gogame

HTML5 version of the Go board game
HTML
7
star
16

cryptopals-challenge

My solutions to challenges at https://cryptopals.com/
Python
6
star
17

framebuffer

Simple and low level C graphics library
C
6
star
18

stack

A toy stack based language
Go
6
star
19

kindle-collections

Automatically generates collections from your directory structure
Go
5
star
20

listregex

Apply regular expressions to lists of arbitrary objects
Python
5
star
21

kahn

Simple and flexible pipeline system for Python
Python
5
star
22

8puzzle

Python solution to sliding 8-puzzle
Python
4
star
23

gl4

Micro game library, v4
JavaScript
4
star
24

cloud_backup_script

Uses rsync to upload immutable files (photos, videos, etc) to a Hetzner Storage Box
Shell
4
star
25

feeder

Dead simple local RSS feed reader
Python
4
star
26

f

The worst Unix program.
Python
4
star
27

ecc

Textbook Elliptic Curve Cryptography for Python and C
C
3
star
28

monty

Library for exploring discrete distributions
Python
3
star
29

shamir

Shamir secret sharing algorithm with threshold detection
Python
3
star
30

markov

Markov chain library to create new data from examples
Python
3
star
31

sciplot

Pythonic data visualization tool
Python
3
star
32

flappy_doge_2048

Tiny, buggy game. Because why not?
JavaScript
3
star
33

typist

Records typing statistics
Python
3
star
34

playreduce

Game based on creating binary finite field reduction algorithms
HTML
3
star
35

flappybot

Auto player for the FlapMMO game
JavaScript
3
star
36

background

Library for Python applications that run in the background
Python
3
star
37

blackcrypto

Library of cryptanalysis tools
Python
2
star
38

web-interact

Two-layer server model for interactivity based on Server-Sent-Events
JavaScript
2
star
39

t

Todo list manager
Python
2
star
40

bop

Experimental Web Framework with Server-Sent-Events
Python
2
star
41

graphql

Basic implementation of GraphQL using in-memory objects
Python
2
star
42

room

Doom-like raytracer
HTML
2
star
43

workspace

Manages programming projects
Python
2
star
44

pycalc

Calculator server with measure unit and Python support
Python
2
star
45

voltorb_flip_solver

Solver for the Pokemon HeartGold game Voltorb Flip
Python
2
star
46

boppreh.github.io

Source code for my homepage
JavaScript
2
star
47

adventofcode_2020

Python
2
star
48

ludum_dare39

Failed to make a game, but the engine rocks!
HTML
2
star
49

speedreader

My try at "Rapid serial visual presentation" (flashing words)
JavaScript
2
star
50

sprawl

Go reimagined as a strategy game
HTML
2
star
51

frango

Authentication system for web services
HTML
2
star
52

adventofcode

My solutions to http://adventofcode.com
Python
2
star
53

gitstatus

Background app for tracking status of local Git repositories
Python
2
star
54

shell

Web-based structured console terminal
HTML
2
star
55

anakata

Anakata is a 4D, tiled, command line puzzle game in Python
Python
2
star
56

jsmatrixboard

Library for highly-interactive matrix-like structures
HTML
2
star
57

goutils

Small Go functions for the everyday programmer
Go
2
star
58

packager

Python script for converting existing projects into PyPi packages
Python
2
star
59

canvasengine

HTML5 Canvas hooks for game bots
JavaScript
2
star
60

poly

Study of polynomials and recurrence relations
Python
2
star
61

gohandlers

Library of HTTP handlers
Go
2
star
62

ppackager

Manage Python packages
Python
2
star
63

gallery

Extracts images from websites and displays in a gallery
Python
2
star
64

gowiki

Very simple wiki server in Go
Go
2
star
65

reduction-circuit

Draws a XOR circuit to perform binary polynomial reduction
HTML
2
star
66

inflist

Infinite lists in Python using lazy evaluation
Python
2
star
67

go-ui

High level Go library for graphical user interfaces
Go
2
star
68

statistical

Small tool for simple statistical tests on samples
2
star
69

dotfiles

My configuration files
Vim Script
2
star
70

telescoping_text

Text with variable amount of details
CSS
2
star
71

dashboard

Attempt at a desktop dashboard with useful functions
Python
2
star
72

console

Cross platform library for simple command line applications
Python
2
star
73

derivative

Library for calculating derivatives using dual numbers
Python
2
star
74

websentinel

Watches webpages for changes and keyword occurences
Python
2
star
75

ludum_dare28

Entry for the 28th Ludum Dare compo
JavaScript
2
star
76

dictfs

Wraps the file system in a dictionary like access structure
Python
2
star
77

ledhero

Guitar-hero like game using only the keyboard LEDs as display
Python
2
star
78

extract_by_pattern

Extract data from texts with no clear field separator
Python
2
star
79

matrix

Pythonic 2D matrix data type
Python
2
star
80

2048bot

Bot for playing the game "2048"
Python
2
star
81

fsm

Fast and simple Finite State Machine library
Python
2
star
82

manual_file_classifier

(k)eep, (d)elete, (r)ename or (m)ove?
Python
2
star
83

switch

Background application responsible for starting and stopping other applications
Python
2
star
84

autokeyboard

Automate everything keyboard
Python
1
star
85

toon_tools

Adds a prefix letter to all files in a given folder
Go
1
star
86

frango-app

Java
1
star
87

activity

Watches, stores and reports user activity on the computer
Python
1
star
88

word2vec_bin_parser

Tiny Python library for parsing Word2Vec .bin embeddings
Python
1
star
89

easier-as3

Tiny functions for common tasks
ActionScript
1
star
90

constraint_propagation

Solver for assigning values to cells via constraint propagation (e.g. Sudoku, Zebra puzzle, seating plan)
Python
1
star
91

attachment

Downloads email attachments you receive and emails attachments you upload
Python
1
star
92

cinema

Finds subtitles and starts playing a movie
Python
1
star
93

symcalc

Symbolic calculator using Python's sympy package
Python
1
star
94

doorman

Notifies when computers enter and exit the wireless network
Python
1
star