Skip to main content

Raspberry Pi USB HID Keyboard + RubberDucky Interpreter

Project description

RPI-HID — Raspberry Pi USB HID Automation Library

RPI-HID is a Python library that allows a Raspberry Pi Zero / Zero 2 W to act as a USB Human Interface Device (HID), emulating a keyboard to automate keystrokes on a connected system.

It provides a high-level API and an advanced Rubber Ducky–style interpreter, abstracting low-level HID report handling into clean, reusable Python functions.


Features

  • USB HID keyboard emulation using Linux USB gadget mode
  • High-level keyboard control API
  • Advanced Rubber Ducky–style script execution
  • Configurable typing delays and pauses
  • Auto-run payload support using systemd
  • Clean, modular, and extensible architecture
  • Published and installable from PyPI

Supported Hardware

  • Raspberry Pi Zero
  • Raspberry Pi Zero 2 W

⚠️ Other Raspberry Pi models (3/4/5) do not support USB gadget mode.


Requirements

  • Raspberry Pi OS (Lite recommended)
  • Python ≥ 3.7
  • USB OTG enabled (dwc2, libcomposite)
  • Root access (required for /dev/hidg0)

Installation

pip install rpi-hid

Quick Start

from rpi_hid import Keyboard

kbd = Keyboard()
kbd.winRun("notepad")
kbd.type("Hello from RPI-HID")
kbd.enter()
kbd.close()

Keyboard API

type(text: str)

Types the given string.

kbd.type("Hello World")

press(*keys)

Presses a key or key combination.

kbd.press("ENTER")
kbd.press("CTRL", "c")
kbd.press("GUI", "r")

pause(seconds: float)

Pauses execution.

kbd.pause(1.5)

winRun(command: str)

Opens the Windows Run dialog and executes a command.

kbd.winRun("cmd")

spamText(text: str, n: int = 10)

Types a string multiple times.

kbd.spamText("TEST ", 5)

Rubber Ducky Script Support

RPI-HID includes a DuckyScript interpreter with near Rubber Ducky v1 compatibility.

Supported Commands

  • STRING
  • DELAY
  • DEFAULT_DELAY
  • STRING_DELAY
  • ENTER, TAB, SPACE, ESC
  • Modifier combos (CTRL, ALT, SHIFT, GUI)
  • REPEAT
  • HOLD, RELEASE
  • REM

Example Ducky Script

REM Demo payload
DEFAULT_DELAY 200
GUI r
STRING notepad
ENTER
STRING Hello from DuckyScript
ENTER

Execute Script

from rpi_hid import DuckyInterpreter

duck = DuckyInterpreter()
duck.run_file("payload.duck")
duck.close()

AutoStart Support

Payload scripts can be configured to run automatically on boot using systemd.

Enable AutoStart

sudo venv/bin/python test.py -a activate

Disable AutoStart

sudo venv/bin/python test.py -a deactivate

List Active AutoStart Scripts

sudo venv/bin/python test.py -a list

Permissions Note

HID device access requires root privileges. When using a virtual environment, always run scripts using the venv Python binary:

sudo venv/bin/python script.py

Ethical Use

This project is intended for:

  • USB HID experimentation
  • Automation on owned or authorized systems
  • Educational and research purposes

Users are responsible for ensuring lawful and ethical use.


License

MIT License


Author

Abhirup Rudra


Future Enhancements

  • Mouse HID support
  • Full Rubber Ducky v2 compatibility
  • Conditional scripting logic
  • GPIO-based payload selection
  • udev-based privilege handling (no sudo)

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

rpi_hid-1.0.10.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

rpi_hid-1.0.10-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file rpi_hid-1.0.10.tar.gz.

File metadata

  • Download URL: rpi_hid-1.0.10.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rpi_hid-1.0.10.tar.gz
Algorithm Hash digest
SHA256 fca20fe1fbc4585fcdc66693092c4117c6128abf09b264241ee5d4147b3e2e95
MD5 3f0a162f8414959a3ebcb902f49e3e2a
BLAKE2b-256 98b139b31f3375a6ea445837c087cf1a26eeb5d7d2f9a80d6a9a3bb19452c108

See more details on using hashes here.

File details

Details for the file rpi_hid-1.0.10-py3-none-any.whl.

File metadata

  • Download URL: rpi_hid-1.0.10-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for rpi_hid-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 cad777628e1381f8d4d1ec751979a3647cd0ceefb9bb8d19084178d28ec047eb
MD5 d7a46b13e0d570ab8a49f551b217bd7b
BLAKE2b-256 23ba1af0d45ccdf20289ee76ba97e49ee5485ba87bbc447bb12565c0726b3933

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