The `keyboard` library for Python provides full control over the keyboard, allowing users to hook global events, register hotkeys, simulate key presses, and much more. It works on Windows and Linux, with experimental support for macOS. The current version is 0.13.5, and it maintains an active development and release cadence.
pip install keyboardVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to simulate key presses, type text, and register complex hotkeys using the `keyboard` library. The program will wait until 'esc' is pressed to terminate.
Run your Python script with `sudo python your_script.py` or configure udev rules for your user to grant access to input devices.
Grant Accessibility permissions via System Preferences/Settings. If issues persist, try running with `sudo` or consider alternative libraries like `pynput` for macOS.
Review logic that relies on raw key names if `get_typed_strings` or event objects are used, and adjust expectations for shifted characters.
If encountering installation errors around version 0.13.1, use `pip install --no-cache keyboard` to force a fresh download and installation.
Avoid mixing `keyboard` event handling with `input()`. If interactive input is needed, implement custom input logic solely using `keyboard` functions, or ensure the input methods are not active concurrently.
Install the package using pip: `pip install keyboard`. Ensure you are installing it into the correct Python environment where your script is being executed.
Rename your Python script file to something other than `keyboard.py` (e.g., `my_script.py`, `key_handler.py`).
Run your Python script with administrator/root privileges. On Linux/macOS, use `sudo python3 your_script.py`. On Windows, run your terminal or IDE as administrator. On macOS, you may also need to grant 'Accessibility' permissions to your terminal/IDE in System Settings.
Ensure the script is run with administrator/root privileges (e.g., `sudo python3 script.py`). Keep the main program alive (e.g., with `keyboard.wait('esc')` or a persistent loop) so hotkeys remain active. On macOS, grant 'Accessibility' permissions to the terminal or IDE. Investigate and disable conflicting background applications if necessary.No dependency data recorded yet.