Map Raspberry Pi GPIO pins to keyboard shortcuts — turn any foot pedal or button into a keystroke
Project description
gpio-pedal
Turn any Raspberry Pi GPIO pin into a keyboard shortcut.
Wire a foot pedal, footswitch, or momentary button to a GPIO pin and gpio-pedal will simulate whatever key press you configure — space bar, Ctrl+C, a media key, anything. Works great for hands-free control, live performance, transcription, accessibility setups, or any situation where your hands are busy.
Features
- Map any number of GPIO pins to individual keys or key combinations (
ctrl+c,shift+f1, etc.) - Configurable debounce time to eliminate phantom presses
- Load config from a JSON or YAML file, or pass a plain Python dict
- CLI command (
gpio-pedal config.json) for running without writing any code - Clean shutdown on Ctrl+C with automatic GPIO cleanup
Requirements
- Raspberry Pi (any model with GPIO)
- Python 3.9 or higher
- A normally-open momentary switch wired between a GPIO pin and GND
Installation
pip install gpio-pedal
For YAML config file support:
pip install gpio-pedal[yaml]
Hardware Setup
Wire your switch between the GPIO pin and GND. gpio-pedal enables the internal pull-up resistor automatically, so no external resistor is needed.
GPIO pin ──── [switch] ──── GND
For example, to use GPIO 17:
Pin 11 (GPIO 17) ──── [foot pedal] ──── Pin 9 (GND)
Use BCM pin numbering (the number after "GPIO", not the physical pin number).
Quick Start
from gpio_pedal import PedalController
config = {
17: "space", # GPIO 17 → Spacebar
22: "ctrl+c", # GPIO 22 → Ctrl+C
27: "m", # GPIO 27 → M key
}
pedal = PedalController(config)
pedal.run()
CLI Usage
Create a JSON config file:
{
"17": "space",
"22": "ctrl+c",
"27": "m"
}
Then run:
gpio-pedal config.json
Options:
gpio-pedal config.json --bouncetime 200 # faster debounce (ms)
gpio-pedal config.json --verbose # debug logging
gpio-pedal --version
gpio-pedal --help
Config File Format
| Format | Extension | Install |
|---|---|---|
| JSON | .json |
built-in |
| YAML | .yaml / .yml |
pip install gpio-pedal[yaml] |
JSON example:
{
"17": "space",
"22": "ctrl+z",
"27": "shift+f5"
}
YAML example:
17: space
22: ctrl+z
27: shift+f5
Keys can be single characters (a, 1, !) or any key name from
pynput's Key enum,
such as space, enter, tab, ctrl, shift, alt, f1–f20, etc.
Combine them with + for shortcuts.
Python API
from gpio_pedal import PedalController, load_config
from gpio_pedal.utils import list_special_keys, describe_config
# Load from a file
config = load_config("config.json")
# Or define inline
config = {17: "space", 22: "ctrl+c"}
# See all supported special key names
print(list_special_keys())
# Preview your config before running
print(describe_config(config))
# Start listening (blocks until Ctrl+C)
controller = PedalController(config, bouncetime=300)
controller.run()
Development
git clone https://github.com/whitneyjsmith/gpio-pedal.git
cd gpio-pedal
pip install -e ".[dev]"
pytest
License
Distributed under the MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gpio_pedal-0.1.1.tar.gz.
File metadata
- Download URL: gpio_pedal-0.1.1.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66821c8867632437ee79052e86abf73297b6fce640e18770834433992771e889
|
|
| MD5 |
7e6888f4eeaa4abe283e38bd15e33643
|
|
| BLAKE2b-256 |
0ba1c7babe2c297f400f8a08bdb6b567610a4bee120a9d7cce810e4c4bcfc122
|
File details
Details for the file gpio_pedal-0.1.1-py3-none-any.whl.
File metadata
- Download URL: gpio_pedal-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f02a0909ca8da422d5257d7c798db563149c6eb38759d6781d2b97f589341d58
|
|
| MD5 |
086a4aa9db8722270f2da05ac1fc3bc8
|
|
| BLAKE2b-256 |
901f47b5dbd19ce4b2d603fce73de6393d13c2d57765048b0813f71b51145b9f
|