#usb #devices #hid #protocols

usbhid

A library for interacting with USB HID devices

1 unstable release

0.1.0 Nov 7, 2023

#1663 in Hardware support

MIT license

18KB
489 lines

🍓 USBHID

Rust Library for the USB HID protocol. Based on zero-hid.

🐛 Compatibility

Compatible Board Port(s)
⚠️ ESP32
⚠️ Raspberry Pi Pico
Raspberry Pi Zero 2w 🎩

Legend: ✅ Compatible, ❌ Incompatible, ⚠️ Untested. Ports: 🎩 USB Hat, 📡 USB Port.

⚡ Features

  • Keyboard.
    • Keydown.
    • Keyup.
    • Type string.
    • Mod keys.
  • Mouse.
    • Move to.
    • Move relative.
    • Left click.
    • Right click.
    • Middle click.
    • Scroll Wheel.
  • Mass storage.
    • Write file.
    • Read file.
    • Delete file.
  • Ethernet.
    • Send packet.
    • Receive packet.
  • Gamepad.
    • Button press.
    • Button release.
    • Joystick move.
  • Printer.
    • Print text.
    • Print image.

⚙ Setup

Before using this library, you need to install a virtual USB HID device on your board.

# Clone the repository
git clone https://github.com/sammwyy/usbhid.git

# Go to the installer directory
cd usbhid/hid

# Install the virtual device
chmod +x install.sh && sudo ./install.sh

📚 Usage

⌨ Keyboard:

use usbhid::{keyboard:Keyboard, device::Device};

fn main() {
    // Install your virtual device before (See documentation)
    let mut device = Device::new("/dev/hidg0");
    let mut keyboard = Keyboard::new(device, "us");

    keyboard.type_string("Hello World!");
}

🖱 Mouse:

use usbhid::{mouse:Mouse, device::Device};

fn main() {
    // Install your virtual device before (See documentation)
    let mut device = Device::new("/dev/hidg1");
    let mut mouse = Mouse::new(device);

    mouse.move_to(100, 100);
    mouse.left_click();
}

🤝 Contributing

Contributions, issues and feature requests are welcome! Feel free to check issues page.

❤️ Show your support

Give a ⭐️ if this project helped you! Or buy me a coffeelatte 🙌 on Ko-fi

📝 License

Copyright © 2023 Sammwy. This project is MIT licensed.

Dependencies

~0.7–1.5MB
~33K SLoC