keyboard
Hook and simulate keyboard events on Windows and Linux
What it is and what it does
keyboard is a Python library that gives you low-level control over keyboard input and output on Windows, Linux, and macOS. It lets you hook global keyboard events (capturing key presses regardless of which window has focus), register complex hotkey combinations, simulate key presses, and record/replay keyboard sequences. The library runs event capture in a separate thread so it doesn't block your main program.
The package is pure Python with no C compilation required, making it trivial to install and deploy. It depends on pyobjc for macOS support. Known limitations include that key suppression only works on Windows, Linux requires root access to read raw device files, and some applications can swallow key events before keyboard sees them.
Use it for:
- Build system-wide hotkey handlers that trigger functions regardless of active window
- Automate repetitive typing tasks by simulating key sequences and text input
- Record keyboard activity for playback at different speeds or for testing
- Create keyboard shortcuts for accessibility or custom application workflows
- Implement text abbreviation expansion (e.g., replace '@@' with an email address)
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Hook global keyboard events, register hotkeys, and simulate key presses across Windows, Linux, and macOS from Python.
Yes, if you need global keyboard control on Windows or Linux. The package is actively maintained, has no known vulnerabilities, and low install friction. On macOS, experimental support means you should test thoroughly before relying on it. Note that Linux requires root/sudo and Windows has the most complete feature set; key suppression is Windows-only.
Install
keyboard on PyPI
pip
pip install keyboarduv
uv add keyboardpoetry
poetry add keyboardInstalling keyboard
Before you install
Low friction install with a single pure-Python runtime dependency (pyobjc). Actively maintained as of July 2026 with 3961 repository stars and steady popularity (top 5000 PyPI packages by downloads).
License in practice
MIT license permits commercial and private use with minimal restrictions; you must include the license notice in distributions.
Quickstart
pip install keyboard
import keyboard
keyboard.add_hotkey('ctrl+shift+a', lambda: keyboard.write('hello'))
keyboard.wait('esc')
Linux requires root/sudo access to read raw device files. Windows and macOS do not require elevated privileges.
Verify before relying
- Whether pyobjc is automatically installed on non-macOS systems or only when needed
- Current state of experimental macOS support and any known stability issues
- Whether key suppression/blocking has been implemented on Linux since the last release
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pyobjc |
| Maintenance | actively maintained — 2,335 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 947,380/month — #4,664 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: keyboard-0.13.5-py3-none-any.whl
Keywords: keyboard, hook, simulate, hotkey
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
sshkeyboardCaptures keyboard input via callbacks in SSH…
permissive · top 15,000 on PyPI
inputsProvides cross-platform Python access to…
permissive · top 15,000 on PyPI
PyAutoGUIPyAutoGUI programmatically controls the mouse…
permissive · top 5,000 on PyPI
pynputPynput lets you programmatically control and…
copyleft · top 5,000 on PyPI
pynput-robocorp-forkControls and monitors mouse and keyboard input…
copyleft · top 15,000 on PyPI
PyDirectInputAutomates mouse and keyboard input on Windows…
permissive · top 15,000 on PyPI
ipyeventsipyevents provides a Jupyter widget that…
permissive · top 15,000 on PyPI
pywinautoAutomate Microsoft Windows GUI interactions by…
permissive · top 5,000 on PyPI
python-yakhCaptures individual keypresses from terminal…
permissive · top 15,000 on PyPI
readcharReads single characters and keystrokes from…
permissive · top 5,000 on PyPI