A Go library for discovering HID (Human Interface Device) raw devices on Linux via sysfs, with built-in USB vendor/device name resolution.
hidraw reads device information from /sys/class/hidraw and returns structured data for each HID raw device, including driver info, HID IDs, and human-readable vendor/device names looked up from the USB ID database.
- Discover all HID raw devices on the system
- Parse HID ID strings into vendor and device IDs
- Look up vendor and device names from an embedded USB ID database
- Optionally load the system USB ID database (
/usr/share/hwdata/usb.ids)
go get github.com/taigrr/hidrawpackage main
import (
"fmt"
"github.com/taigrr/hidraw"
)
func main() {
devs := hidraw.Walk()
for _, d := range devs {
fmt.Printf("%s: %s", d.PathName, d.HidName)
if d.VendorName != "" {
fmt.Printf(" [%s", d.VendorName)
if d.DeviceName != "" {
fmt.Printf(" — %s", d.DeviceName)
}
fmt.Print("]")
}
fmt.Println()
}
}Discovers all hidraw devices. Errors reading individual devices are silently ignored.
Like Walk, but returns an error if the hidraw sysfs directory cannot be walked.
import usbid "github.com/taigrr/hidraw/usbids"
// Look up by ID
name := usbid.LookupVendor(usbid.ID(0x046d)) // "Logitech, Inc."
name = usbid.LookupDevice(usbid.ID(0x046d), usbid.ID(0xc52b))
name = usbid.LookupInterface(usbid.ID(0x046d), usbid.ID(0xc52b), usbid.ID(0x00))
// Load system DB instead of embedded
usbid.LoadSystemDB()
// Parse a custom usb.ids file
vendors, err := usbid.Parse(reader)- Linux operating system
- Go 1.26 or later
- Access to
/sys/class/hidrawdirectory
0BSD — see LICENSE.
