iohidmanager 0.3.0

Safe Rust bindings for Apple's IOKit HID — enumerate connected mice, keyboards, gamepads, and other HID devices on macOS
Documentation

iohidmanager

Safe Rust bindings for Apple's IOKit HID subsystem on macOS — enumerate connected mice, keyboards, gamepads, and other HID devices.

Status: experimental. v0.1 ships device enumeration + property snapshots (vendor / product / manufacturer / usage page / serial / transport). Live input-report subscription via IOHIDDeviceRegisterInputReportCallback lands in v0.2.

Pure C — zero Swift bridge (like cgevents, imageio, videotoolbox).

Quick start

use iohidmanager::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let manager = HidManager::new()?;
    manager.set_device_matching(None)?;  // all devices

    for d in manager.devices() {
        println!(
            "[{:04x}:{:04x}] {}{} ({})",
            d.vendor_id.unwrap_or(0),
            d.product_id.unwrap_or(0),
            d.manufacturer.as_deref().unwrap_or("?"),
            d.product.as_deref().unwrap_or("?"),
            d.transport.as_deref().unwrap_or("?")
        );
    }

    // Filter to keyboards only.
    let kb = HidManager::new()?;
    kb.set_device_matching(Some(HidUsage::Keyboard))?;
    println!("\n{} keyboards connected:", kb.devices().len());
    for d in kb.devices() {
        println!("  - {}", d.product.as_deref().unwrap_or("?"));
    }
    Ok(())
}

Pipeline composition

iohidmanager (enumerate) ──► your custom dispatch
                              │
                              ├─► gamepad-mapper
                              ├─► macropad-driver
                              └─► hardware-token authentication

Pairs naturally with cgevents (synthesise events triggered by HID input) and carbonhotkey (more focused: just global hotkeys).

Roadmap

  • HidManager::new() + open
  • set_device_matching(Option<HidUsage>) filter
  • devices() enumeration with vendor/product/usage/serial/transport
  • HidUsage enum with Keyboard / Mouse / Joystick / GamePad presets
  • Live input-report callbacks (IOHIDDeviceRegisterInputReportCallback)
  • Element discovery (IOHIDDeviceCopyMatchingElements + IOHIDElementGetUsage)
  • Synchronous report read / write (IOHIDDeviceGetReport / SetReport)
  • Run-loop integration (IOHIDManagerScheduleWithRunLoop)
  • Async API

License

Licensed under either of Apache-2.0 or MIT at your option.