keyboard is a Python library that hooks and simulates global keyboard events on Windows and Linux.
The library solves the problem of capturing keyboard input globally, regardless of which application has focus, and simulating key presses programmatically. It works by installing system-level keyboard hooks that operate in a separate thread, allowing applications to listen for and respond to keyboard events without blocking the main program. The tool supports complex hotkey combinations with configurable timeouts and includes high-level APIs for recording and playing back keyboard sequences, as well as text abbreviation expansion. It handles keyboard layouts correctly through full internationalization support, allowing developers to work with keys as they appear in the user's actual layout rather than raw scancodes.
The tool suits projects that need global keyboard monitoring or automation on Windows or Linux systems. It requires no compilation or external dependencies, making deployment straightforward—the source files can simply be copied into a project. Developers should be aware that the project is currently unmaintained, though it works for many use cases. Key limitations include that key suppression only works on Windows, Linux usage requires root access to read raw device files, and media keys on Linux may not be recognized. The library cannot detect keyboard events if other applications have registered hooks that consume all events, and it should not be used for keylogging or online gaming automation.
Development activity shows infrequent commits with substantial gaps between updates. The project has accumulated unresolved issues related to platform-specific functionality, including device identification on Windows, media key support on Linux, and key blocking capabilities. Documentation exists but remains incomplete relative to the full API surface. The codebase supports both Python 2 and 3, though this dual compatibility is increasingly outdated.