pynput
Monitor and control user input devices
What it is and what it does
Pynput is a cross-platform library for controlling and monitoring mouse and keyboard input devices from Python. It provides a Controller class to programmatically move the mouse, click buttons, type text, and press keys, as well as Listener classes to detect and react to mouse and keyboard events in real time. The library abstracts away platform differences—using native APIs on Windows, macOS, and Linux—so you write once and run on all three.
Typical use cases include automation scripts, testing frameworks that need to simulate user input, accessibility tools, and interactive applications that respond to keyboard or mouse events. The listener runs in a background thread and invokes callbacks for each event, while the controller lets you inject input as if a user had performed it. The library is mature (first released in 2015, marked Production/Stable) and actively maintained, with no known security vulnerabilities.
Use it for:
- Automate repetitive UI tasks: script mouse clicks and keyboard input to control applications without modifying them.
- Test GUI applications: inject mouse and keyboard events to verify that user interfaces respond correctly to input.
- Build accessibility tools: monitor keyboard and mouse activity to create overlays, remapping utilities, or input assistants.
- Create interactive scripts: listen for keyboard shortcuts or mouse gestures to trigger custom actions in a background process.
- Develop game automation or bot tools: control game input and respond to on-screen events programmatically.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pynput lets you programmatically control and monitor mouse and keyboard input across Windows, macOS, and Linux from Python code.
Yes, if you need cross-platform input control and monitoring. Pynput is stable, actively maintained, has no known vulnerabilities, and handles platform differences transparently. The LGPLv3 license is permissive for most use cases (including proprietary software) as long as you disclose the library and its modifications. Main caveat: Linux installations may require system development headers; plan for that in CI/CD or deployment.
Install
pynput on PyPI
pip
pip install pynputuv
uv add pynputpoetry
poetry add pynputInstalling pynput
Before you install
Low install friction; distributed as a pure Python wheel. Depends on platform-specific libraries (pyobjc frameworks on macOS, evdev and python-xlib on Linux) that pip will pull automatically, but these may require system development headers on some Linux distributions.
License in practice
Licensed under LGPLv3 (copyleft). You may use pynput in proprietary software, but any modifications to pynput itself must be released under the same license, and you must disclose the library's presence and provide access to its source.
Quickstart
from pynput.mouse import Controller, Button
from pynput.keyboard import Controller as KeyboardController
mouse = Controller()
mouse.position = (100, 100)
mouse.click(Button.left, 1)
keyboard = KeyboardController()
keyboard.type('Hello World')
On Linux, requires libxlib development headers and evdev library; on macOS, requires Xcode command-line tools or pyobjc frameworks; Windows typically has no additional system requirements.
Verify before relying
- Whether enum34 is still required for modern Python versions or is a legacy dependency
- Specific Python version floor and ceiling for version 1.8.2
- Whether the library works reliably in headless/server environments or requires an active display
Package facts
| License | LGPLv3 (copyleft) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — six, pyobjc-framework-ApplicationServices, pyobjc-framework-Quartz, evdev, python-xlib, enum34 |
| Maintenance | actively maintained — 94 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,285,530/month — #3,163 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pynput-1.8.2-py2.py3-none-any.whl
Keywords: control mouse, mouse input, control keyboard, keyboard input
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
inputsProvides cross-platform Python access to…
permissive · top 15,000 on PyPI
pynput-robocorp-forkControls and monitors mouse and keyboard input…
copyleft · top 15,000 on PyPI
sshkeyboardCaptures keyboard input via callbacks in SSH…
permissive · top 15,000 on PyPI
PyAutoGUIPyAutoGUI programmatically controls the mouse…
permissive · top 5,000 on PyPI
evdevProvides Python bindings to Linux's evdev and…
permissive · top 5,000 on PyPI
keyboardHook global keyboard events, register hotkeys,…
permissive · top 5,000 on PyPI
PyAutoItPyAutoIt provides Python bindings to…
permissive · top 15,000 on PyPI
PyDirectInputAutomates mouse and keyboard input on Windows…
permissive · top 15,000 on PyPI
MouseInfoMouseInfo displays the XY coordinates and RGB…
copyleft · top 5,000 on PyPI
pywinautoAutomate Microsoft Windows GUI interactions by…
permissive · top 5,000 on PyPI