# keyboard: Python Library for Global Keyboard Event Control

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Source: osrepos.com
Repository profile: https://osrepos.com/repo/boppreh-keyboard
Generated for open source discovery and AI-assisted research.

The `keyboard` library is a powerful Python tool designed to hook and simulate global keyboard events across Windows and Linux, with experimental macOS support. It offers comprehensive control over keyboard interactions, allowing users to listen for events, register complex hotkeys, and simulate key presses. Despite being currently unmaintained, it remains a functional solution for many use cases requiring direct keyboard manipulation.

GitHub: https://github.com/boppreh/keyboard
OSRepos URL: https://osrepos.com/repo/boppreh-keyboard

## Summary

The `keyboard` library is a powerful Python tool designed to hook and simulate global keyboard events across Windows and Linux, with experimental macOS support. It offers comprehensive control over keyboard interactions, allowing users to listen for events, register complex hotkeys, and simulate key presses. Despite being currently unmaintained, it remains a functional solution for many use cases requiring direct keyboard manipulation.

## Topics

- python
- keyboard-events
- hotkey
- keyboard-hooks
- automation
- system-utility
- callback
- scancode

## Repository Information

Last analyzed by OSRepos: Wed Jan 21 2026 12:01:03 GMT+0000 (Western European Standard Time)
Detail views: 4
GitHub clicks: 6

## Safety Notice

OSRepos shares public repositories for knowledge and discovery only. Review source code, dependencies, licenses, and security implications before running or installing anything.

## Content

## Introduction

The `keyboard` library by boppreh is a versatile Python tool that provides full control over global keyboard events. It allows developers to hook into keyboard events, register custom hotkeys, and simulate key presses on Windows, Linux, and experimentally on macOS. While the project is currently unmaintained, it offers a robust set of features for many applications requiring direct interaction with the keyboard.

## Installation

Getting started with `keyboard` is straightforward. You can install it via pip or by cloning the repository directly.

To install using pip:
bash
pip install keyboard


Alternatively, you can clone the GitHub repository, as no installation is required; the source files are sufficient:
bash
git clone https://github.com/boppreh/keyboard


## Examples

The `keyboard` library offers a high-level API for various keyboard interactions. Here are a few examples to illustrate its capabilities:

### Simulating Key Presses and Typing:
python
import keyboard

# Press and release a hotkey combination
keyboard.press_and_release('shift+s, space')

# Type a string of text
keyboard.write('The quick brown fox jumps over the lazy dog.')


### Registering Hotkeys:
python
# Register a hotkey to print a message
keyboard.add_hotkey('ctrl+shift+a', print, args=('triggered', 'hotkey'))

# Register a multi-step hotkey to type text
keyboard.add_hotkey('page up, page down', lambda: keyboard.write('foobar'))


### Recording and Playing Events:
python
# Blocks until 'esc' is pressed, recording all events
recorded = keyboard.record(until='esc')
# Replay the recorded events at three times the speed
keyboard.play(recorded, speed_factor=3)


### Creating Abbreviations:
python
# Type '@@' then press space to replace with an email address
keyboard.add_abbreviation('@@', 'my.long.email@example.com')


### Waiting for a Key Press:
python
# Blocks the program until 'esc' is pressed
keyboard.wait('esc')


## Why Use It

The `keyboard` library stands out for several reasons:

*   **Global Event Hook**: Captures key events regardless of the active window's focus.
*   **Cross-Platform Support**: Works on Windows, Linux (requires sudo), and offers experimental macOS support.
*   **Pure Python & Zero Dependencies**: Easy to install and deploy without complex compilation or external requirements.
*   **Internationalization**: Maps keys according to your actual keyboard layout, supporting international characters like `Ctrl+ç`.
*   **Complex Hotkey Support**: Allows for intricate hotkey combinations and sequences (e.g., `ctrl+shift+m, ctrl+space`).
*   **High-Level API**: Includes convenient functions for recording/playing events and adding abbreviations.
*   **Asynchronous Event Handling**: Events are captured in a separate thread, preventing the main program from blocking.

## Links

You can find more information, contribute, or report issues by visiting the official repository and PyPI page:

*   [GitHub Repository](https://github.com/boppreh/keyboard)
*   [PyPI Package](https://pypi.python.org/pypi/keyboard/)