skillfed

pynput

Monitor and control user input devices

pynput v1.8.2 2.3M downloads/30d#3,163 on PyPI2,165
Copyleft license LGPLv3 Active released

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 pynput

uv

uv add pynput

poetry

poetry add pynput

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)Operating System :: MacOS :: MacOS XOperating System :: Microsoft :: Windows :: Windows NT/2000Operating System :: POSIXProgramming Language :: PythonProgramming Language :: Python :: 2.7Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python ModulesTopic :: System :: Monitoring

Tags

mouse keyboard control pythoninput device automationsimulate mouse clicks keyboardmonitor keyboard mouse eventscross-platform input controlkeyboard mouse listenerprogrammatic input injection
input-automationcross-platformgui-testing

More Python Modules packages