{"id":13456823,"url":"https://github.com/libusb/hidapi","last_synced_at":"2025-05-14T10:06:39.817Z","repository":{"id":37269946,"uuid":"190275430","full_name":"libusb/hidapi","owner":"libusb","description":"A Simple cross-platform library for communicating with HID devices","archived":false,"fork":false,"pushed_at":"2025-05-06T17:57:39.000Z","size":3490,"stargazers_count":1837,"open_issues_count":51,"forks_count":425,"subscribers_count":45,"default_branch":"master","last_synced_at":"2025-05-06T18:49:15.715Z","etag":null,"topics":["android","bluetooth","bsd","c","hid","hidapi","hidapi-library","hidraw","i2c","linux","macos","spi","usb","usb-hid","windows"],"latest_commit_sha":null,"homepage":"https://libusb.info/hidapi/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libusb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-bsd.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-06-04T20:36:19.000Z","updated_at":"2025-05-06T17:57:16.000Z","dependencies_parsed_at":"2024-04-06T10:25:52.551Z","dependency_job_id":"5292d54f-f4db-475d-921d-6c0e70f352fb","html_url":"https://github.com/libusb/hidapi","commit_stats":{"total_commits":617,"total_committers":127,"mean_commits":4.858267716535433,"dds":0.6418152350081037,"last_synced_commit":"6c2de304317d2e48c463399e0401ae6e406cd7c6"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libusb%2Fhidapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libusb%2Fhidapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libusb%2Fhidapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libusb%2Fhidapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libusb","download_url":"https://codeload.github.com/libusb/hidapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254119484,"owners_count":22017951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","bluetooth","bsd","c","hid","hidapi","hidapi-library","hidraw","i2c","linux","macos","spi","usb","usb-hid","windows"],"created_at":"2024-07-31T08:01:28.392Z","updated_at":"2025-05-14T10:06:39.808Z","avatar_url":"https://github.com/libusb.png","language":"C","readme":"## HIDAPI library for Windows, Linux, FreeBSD and macOS\n\n| CI instance          | Status |\n|----------------------|--------|\n| `Linux/macOS/Windows (master)` | [![GitHub Builds](https://github.com/libusb/hidapi/actions/workflows/builds.yml/badge.svg?branch=master)](https://github.com/libusb/hidapi/actions/workflows/builds.yml?query=branch%3Amaster) |\n| `Windows (master)` | [![Build status](https://ci.appveyor.com/api/projects/status/xfmr5fo8w0re8ded/branch/master?svg=true)](https://ci.appveyor.com/project/libusb/hidapi/branch/master) |\n| `BSD, last build (branch/PR)` | [![builds.sr.ht status](https://builds.sr.ht/~z3ntu/hidapi.svg)](https://builds.sr.ht/~z3ntu/hidapi) |\n| `Coverity Scan (last)` | [![Coverity Scan](https://scan.coverity.com/projects/583/badge.svg)](https://scan.coverity.com/projects/hidapi) |\n\nHIDAPI is a multi-platform library which allows an application to interface\nwith USB and Bluetooth HID-Class devices on Windows, Linux, FreeBSD, and macOS.\nHIDAPI can be either built as a shared library (`.so`, `.dll` or `.dylib`) or\ncan be embedded directly into a target application by adding a _single source_\nfile (per platform) and a single header.\u003cbr\u003e\nSee [remarks](BUILD.md#embedding-hidapi-directly-into-your-source-tree) on embedding _directly_ into your build system.\n\nHIDAPI library was originally developed by Alan Ott ([signal11](https://github.com/signal11)).\n\nIt was moved to [libusb/hidapi](https://github.com/libusb/hidapi) on June 4th, 2019, in order to merge important bugfixes and continue development of the library.\n\n## Table of Contents\n\n* [About](#about)\n    * [Test GUI](#test-gui)\n    * [Console Test App](#console-test-app)\n* [What Does the API Look Like?](#what-does-the-api-look-like)\n* [License](#license)\n* [Installing HIDAPI](#installing-hidapi)\n* [Build from Source](#build-from-source)\n\n\n## About\n\n### HIDAPI has four back-ends:\n* Windows (using `hid.dll`)\n* Linux/hidraw (using the Kernel's hidraw driver)\n* libusb (using libusb-1.0 - Linux/BSD/other UNIX-like systems)\n* macOS (using IOHidManager)\n\nOn Linux, either the hidraw or the libusb back-end can be used. There are\ntradeoffs, and the functionality supported is slightly different. Both are\nbuilt by default. It is up to the application linking to hidapi to choose\nthe backend at link time by linking to either `libhidapi-libusb` or\n`libhidapi-hidraw`.\n\nNote that you will need to install an udev rule file with your application\nfor unprivileged users to be able to access HID devices with hidapi. Refer\nto the [69-hid.rules](udev/69-hid.rules) file in the `udev` directory\nfor an example.\n\n#### __Linux/hidraw__ (`linux/hid.c`):\n\nThis back-end uses the hidraw interface in the Linux kernel, and supports\nboth USB and Bluetooth HID devices. It requires kernel version at least 2.6.39\nto build. In addition, it will only communicate with devices which have hidraw\nnodes associated with them.\nKeyboards, mice, and some other devices which are blacklisted from having\nhidraw nodes will not work. Fortunately, for nearly all the uses of hidraw,\nthis is not a problem.\n\n#### __Linux/FreeBSD/libusb__ (`libusb/hid.c`):\n\nThis back-end uses libusb-1.0 to communicate directly to a USB device. This\nback-end will of course not work with Bluetooth devices.\n\n### Test GUI\n\nHIDAPI also comes with a Test GUI. The Test GUI is cross-platform and uses\nFox Toolkit \u003chttp://www.fox-toolkit.org\u003e.  It will build on every platform\nwhich HIDAPI supports.  Since it relies on a 3rd party library, building it\nis optional but it is useful when debugging hardware.\n\nNOTE: Test GUI based on Fox Toolkit is not actively developed nor supported\nby HIDAPI team. It is kept as a historical artifact. It may even work sometime\nor on some platforms, but it is not going to get any new features or bugfixes.\n\nInstructions for installing Fox-Toolkit on each platform is not provided.\nMake sure to use Fox-Toolkit v1.6 if you choose to use it.\n\n### Console Test App\n\nIf you want to play around with your HID device before starting\nany development with HIDAPI and using a GUI app is not an option for you, you may try [`hidapitester`](https://github.com/todbot/hidapitester).\n\nThis app has a console interface for most of the features supported\nby HIDAPI library.\n\n## What Does the API Look Like?\n\nThe API provides the most commonly used HID functions including sending\nand receiving of input, output, and feature reports. The sample program,\nwhich communicates with a heavily hacked up version of the Microchip USB\nGeneric HID sample looks like this (with error checking removed for\nsimplicity):\n\n**Warning: Only run the code you understand, and only when it conforms to the\ndevice spec. Writing data (`hid_write`) at random to your HID devices can break them.**\n\n```c\n#include \u003cstdio.h\u003e // printf\n#include \u003cwchar.h\u003e // wchar_t\n\n#include \u003chidapi.h\u003e\n\n#define MAX_STR 255\n\nint main(int argc, char* argv[])\n{\n\tint res;\n\tunsigned char buf[65];\n\twchar_t wstr[MAX_STR];\n\thid_device *handle;\n\tint i;\n\n\t// Initialize the hidapi library\n\tres = hid_init();\n\n\t// Open the device using the VID, PID,\n\t// and optionally the Serial number.\n\thandle = hid_open(0x4d8, 0x3f, NULL);\n\tif (!handle) {\n\t\tprintf(\"Unable to open device\\n\");\n\t\thid_exit();\n \t\treturn 1;\n\t}\n\n\t// Read the Manufacturer String\n\tres = hid_get_manufacturer_string(handle, wstr, MAX_STR);\n\tprintf(\"Manufacturer String: %ls\\n\", wstr);\n\n\t// Read the Product String\n\tres = hid_get_product_string(handle, wstr, MAX_STR);\n\tprintf(\"Product String: %ls\\n\", wstr);\n\n\t// Read the Serial Number String\n\tres = hid_get_serial_number_string(handle, wstr, MAX_STR);\n\tprintf(\"Serial Number String: (%d) %ls\\n\", wstr[0], wstr);\n\n\t// Read Indexed String 1\n\tres = hid_get_indexed_string(handle, 1, wstr, MAX_STR);\n\tprintf(\"Indexed String 1: %ls\\n\", wstr);\n\n\t// Toggle LED (cmd 0x80). The first byte is the report number (0x0).\n\tbuf[0] = 0x0;\n\tbuf[1] = 0x80;\n\tres = hid_write(handle, buf, 65);\n\n\t// Request state (cmd 0x81). The first byte is the report number (0x0).\n\tbuf[0] = 0x0;\n\tbuf[1] = 0x81;\n\tres = hid_write(handle, buf, 65);\n\n\t// Read requested state\n\tres = hid_read(handle, buf, 65);\n\n\t// Print out the returned buffer.\n\tfor (i = 0; i \u003c 4; i++)\n\t\tprintf(\"buf[%d]: %d\\n\", i, buf[i]);\n\n\t// Close the device\n\thid_close(handle);\n\n\t// Finalize the hidapi library\n\tres = hid_exit();\n\n\treturn 0;\n}\n```\n\nYou can also use [hidtest/test.c](hidtest/test.c)\nas a starting point for your applications.\n\n\n## License\n\nHIDAPI may be used by one of three licenses as outlined in [LICENSE.txt](LICENSE.txt).\n\n## Installing HIDAPI\n\nIf you want to build your own application that uses HID devices with HIDAPI,\nyou need to get HIDAPI development package.\n\nDepending on what your development environment is, HIDAPI likely to be provided\nby your package manager.\n\nFor instance on Ubuntu, HIDAPI is available via APT:\n```sh\nsudo apt install libhidapi-dev\n```\n\nHIDAPI package name for other systems/package managers may differ.\nCheck the documentation/package list of your package manager.\n\n## Build from Source\n\nCheck [BUILD.md](BUILD.md) for details.\n","funding_links":[],"categories":["C","HarmonyOS"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibusb%2Fhidapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibusb%2Fhidapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibusb%2Fhidapi/lists"}