• Stars
    star
    902
  • Rank 50,637 (Top 1.0 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated 5 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,791
star
2

steamgrid

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

maze

Simple maze generator in Python
Python
62
star
4

server-sent-events

Python library for Server-Sent-Events
Python
39
star
5

bayesian

Utility for Bayesian reasoning
Python
37
star
6

hello_tls

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

minetesting

Client and mod for the Minetest game
Logos
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

structured-editor

Structured editor for general purpose programming languages
Python
9
star
12

carlo

Interactively plot streaming sequences of numbers
Python
9
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
7
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

cloud_backup_script

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

listregex

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

kahn

Simple and flexible pipeline system for Python
Python
5
star
23

8puzzle

Python solution to sliding 8-puzzle
Python
4
star
24

gl4

Micro game library, v4
JavaScript
4
star
25

f

The worst Unix program.
Python
4
star
26

feeder

Dead simple local RSS feed reader
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

playreduce

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

shamir

Shamir secret sharing algorithm with threshold detection
Python
3
star
31

markov

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

sciplot

Pythonic data visualization tool
Python
3
star
33

flappy_doge_2048

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

typist

Records typing statistics
Python
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

web-interact

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

blackcrypto

Library of cryptanalysis tools
Python
2
star
39

t

Todo list manager
Python
2
star
40

room

Doom-like raytracer
HTML
2
star
41

voltorb_flip_solver

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

boppreh.github.io

Source code for my homepage
JavaScript
2
star
43

adventofcode_2020

Python
2
star
44

workspace

Manages programming projects
Python
2
star
45

speedreader

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

frango

Authentication system for web services
HTML
2
star
47

ludum_dare39

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

sprawl

Go reimagined as a strategy game
HTML
2
star
49

gitstatus

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

shell

Web-based structured console terminal
HTML
2
star
51

anakata

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

jsmatrixboard

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

goutils

Small Go functions for the everyday programmer
Go
2
star
54

bop

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

canvasengine

HTML5 Canvas hooks for game bots
JavaScript
2
star
56

poly

Study of polynomials and recurrence relations
Python
2
star
57

gohandlers

Library of HTTP handlers
Go
2
star
58

packager

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

ppackager

Manage Python packages
Python
2
star
60

gowiki

Very simple wiki server in Go
Go
2
star
61

inflist

Infinite lists in Python using lazy evaluation
Python
2
star
62

go-ui

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

statistical

Small tool for simple statistical tests on samples
2
star
64

dotfiles

My configuration files
Vim Script
2
star
65

gallery

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

telescoping_text

Text with variable amount of details
CSS
2
star
67

dashboard

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

console

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

derivative

Library for calculating derivatives using dual numbers
Python
2
star
70

adventofcode

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

websentinel

Watches webpages for changes and keyword occurences
Python
2
star
72

ludum_dare28

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

graphql

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

dictfs

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

ledhero

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

extract_by_pattern

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

matrix

Pythonic 2D matrix data type
Python
2
star
78

reduction-circuit

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

2048bot

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

manual_file_classifier

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

fsm

Fast and simple Finite State Machine library
Python
2
star
82

switch

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

pycalc

Calculator server with measure unit and Python support
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

cinema

Finds subtitles and starts playing a movie
Python
1
star
90

easier-as3

Tiny functions for common tasks
ActionScript
1
star
91

constraint_propagation

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

attachment

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

doorman

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

symcalc

Symbolic calculator using Python's sympy package
Python
1
star