iohidmanager
Safe Rust bindings for Apple's IOKit HID subsystem on macOS — enumerate connected mice, keyboards, gamepads, and other HID devices.
Status: actively developed. v0.6 ships a Swift bridge for
IOKit/hid, keeps the raw C surface behind theraw-ffifeature (enabled by default), and adds logical-area coverage for Manager, Device, Element, Value, Transaction, Queue, Keys, Usage, ServicePlugIn, and EventSystem.
Quick start
use *;
Highlights in v0.6
- Swift bridge target under
swift-bridge/with one Swift file per logical area. raw-ffiCargo feature (enabled by default) re-exporting the rawIOKit/hiddeclarations.- New safe transaction and queue wrappers:
HidTransaction,HidTransactionDirection,HidQueue, andHidQueueOptions. - Manager matching helpers for input-value filtering.
- Device helpers for multi-value reads/writes, removal callbacks, and timeout-based value/report setters.
- Element attach/detach helpers.
unsafe { HidValue::from_bytes_no_copy(...) }bridged through Swift.- Generated
keysandusagecatalogs, event-system constants, and service-plugin UUID helpers. - 15 runnable examples and per-area smoke tests.
Feature flags
raw-ffi(default) — re-export the rawiohidmanager::ffimodule.
Disable default features if you only want the safe surface:
Area guide
- Manager — device matching, properties, enumeration, and manager-level filtering.
- Device — properties, reports, synchronous values, multi-value helpers, and removal subscriptions.
- Element — hierarchy traversal, metadata, and attach/detach relationships.
- Value — integer/byte constructors, no-copy bridge constructor, typed accessors.
- Transaction — batched input/output element transactions.
- Queue — buffered value delivery and queue depth management.
- Keys — generated string/numeric key catalog from
IOHIDKeys.h,IOHIDDeviceKeys.h, andIOHIDProperties.h. - Usage — generated usage/page constant catalog from
IOHIDUsageTables.h. - ServicePlugIn — UUID helpers for the
IOHIDDevicePlugIn.hinterfaces. - EventSystem —
IOHIDEventServiceKeys.handIOHIDEventServiceTypes.hconstants.
Examples
The crate ships 15 examples, including:
06_manager_callbacks07_device_roundtrip08_element_attachment09_value_constructors10_transaction_roundtrip11_queue_roundtrip12_keys_catalog13_usage_catalog14_service_plugin_ids15_event_system_catalog
Run them all with:
for; do ; done
Pipeline composition
iohidmanager (enumerate + inspect + subscribe) ──► 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 -
DeviceMatch/ElementMatchbuilders + multi-match dictionaries - device enumeration and live device handles
- report/value callbacks on devices
- manager input-value matching helpers
-
HidTransactionandHidQueue -
unsafe HidValue::from_bytes_no_copy - generated keys/usage catalogs
- service-plugin UUID helpers and event-system constants
- Swift bridge +
raw-ffifeature split
License
Licensed under either of Apache-2.0 or MIT at your option.