pynput
Sends virtual input commands
A Python library that lets your code control the mouse and keyboard, or listen for what a person is typing and clicking, across Windows, Mac, and Linux.
pynput
This is a Python library that lets you control your mouse and keyboard from code, and also monitor what keys and mouse movements someone (or some program) is making on a computer. Think of it as a remote control for your input devices.
At its core, pynput does two things. First, it can simulate user input—you can write code that moves the mouse cursor, clicks buttons, or types text, as if a real person were doing it. Second, it can listen to and record what's happening with the keyboard and mouse, letting you detect when keys are pressed or the mouse moves. The library handles the tricky platform-specific stuff behind the scenes, so your Python code works the same way on Windows, Mac, and Linux without you having to rewrite anything.
People use this for a few common reasons. Automation enthusiasts use it to script repetitive tasks—like automating clicks in a game, filling out forms, or controlling applications. Developers building accessibility tools might use it to let people with limited mobility control a computer through alternative input methods. Security researchers and testers sometimes use it to simulate user behavior or test how software responds to keyboard and mouse input. And game developers occasionally use it to add automated demo modes or testing capabilities.
The library is straightforward to work with: you import it, tell it what input action you want to perform (or what to listen for), and it handles the rest. Since it's just a Python package, you can integrate it into larger scripts or applications pretty easily. The documentation is available online if you need more details on how to use specific features.
Where it fits
- Automate repetitive mouse clicks or keyboard input, like filling out forms or scripting a game.
- Build accessibility tools that let people control a computer through alternative input methods.
- Simulate user behavior to test how software responds to keyboard and mouse input.
- Add automated demo or testing modes to a game or application.