Skip to main content

Map Raspberry Pi GPIO pins to keyboard shortcuts — turn any foot pedal or button into a keystroke

Project description

gpio-pedal

PyPI Version Python Versions License

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, f1f20, 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpio_pedal-0.1.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpio_pedal-0.1.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file gpio_pedal-0.1.0.tar.gz.

File metadata

  • Download URL: gpio_pedal-0.1.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for gpio_pedal-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2074ba798bffc70ed846a0bb4a905aaccad383786d8caa67c985b1b01c9250a6
MD5 57469795619bcb22bf80efe4175b73a3
BLAKE2b-256 faed8081f6a719becd0e3059cbe749f5d7f2a56e2b7a28c6c1ee585f0ba8162d

See more details on using hashes here.

File details

Details for the file gpio_pedal-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gpio_pedal-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for gpio_pedal-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b9c05ae365d7274378c5c56c976672d06f5d5762ded85d1bc14ed618f412bd4
MD5 29f91f9ebd572ef9ae233f2836075f82
BLAKE2b-256 f5c243f8bd04f5efe29096622266f2d223f121c7b056a4380264bd565dcc1891

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page