hidapi 0.1.5 copy "hidapi: ^0.1.5" to clipboard
hidapi: ^0.1.5 copied to clipboard

Cross-platform Dart bindings for hidapi — the de facto C library for USB HID access. Compiles hidapi from vendored source via Dart build hooks.

hidapi #

Dart FFI bindings for hidapi — the cross-platform C library for USB and Bluetooth HID device access.

Compiles hidapi 0.15.0 from source at build time via Dart build hooks. No system-level hidapi installation required.

Why this package? #

  • Pure Dart. No Flutter dependency. Works in CLI tools, servers, and any Dart application.
  • Modern build. Uses Dart 3.10 native build hooks to compile hidapi from vendored source. No manual toolchain setup beyond a C compiler.
  • Complete API. Wraps every public hidapi function — enumerate, open, read/write, feature and input reports, report descriptors, string queries, device info, and version introspection.

Platform support #

Platform Backend
Windows windows/hid.c
macOS mac/hid.c
Linux linux/hid.c

Requirements #

  • Dart SDK >=3.10.0
  • A C toolchain (MSVC, Clang, or GCC) reachable by native_toolchain_c
  • Linux: libudev-dev (or equivalent)

Install #

dart pub add hidapi

Usage #

import 'package:hidapi/hidapi.dart';

void main() {
  hidInit();
  try {
    // List all HID devices (0, 0 = match any VID/PID)
    final devices = hidEnumerate();
    for (final d in devices) {
      print('${d.manufacturer} ${d.product} — ${d.path}');
    }

    // Open a specific device by path
    if (devices.isNotEmpty) {
      final dev = hidOpenPath(devices.first.path);
      try {
        dev.setNonBlocking(true);
        final data = dev.read(64, timeout: Duration(milliseconds: 100));
        print('Read ${data.length} bytes');
      } finally {
        dev.close();
      }
    }
  } finally {
    hidExit();
  }
}

API #

Top-level functions: hidInit, hidExit, hidEnumerate, hidOpen, hidOpenPath, hidVersion, hidVersionStr.

HidDevice wraps an open device handle with methods for read/write, feature and input reports, report descriptors, string queries, and non-blocking mode.

See the API reference for full details.

How the build works #

The Dart build hook downloads a pinned, SHA-256-verified hidapi tarball on first build and caches it. No manual steps beyond a C toolchain.

Upstream #

libusb/hidapi — originally signal11/hidapi, now maintained under the libusb org.

Issues and contributions #

File bugs and feature requests on the issue tracker.

License #

See LICENSE.

1
likes
160
points
222
downloads

Publisher

unverified uploader

Weekly Downloads

Cross-platform Dart bindings for hidapi — the de facto C library for USB HID access. Compiles hidapi from vendored source via Dart build hooks.

Repository (GitHub)
View/report issues

Topics

#hid #usb #ffi #native

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

archive, code_assets, crypto, ffi, hooks, native_toolchain_c

More

Packages that depend on hidapi