{"id":13560833,"url":"https://github.com/signal11/hidapi","last_synced_at":"2025-05-14T22:09:50.354Z","repository":{"id":41371472,"uuid":"605459","full_name":"signal11/hidapi","owner":"signal11","description":"A Simple library for communicating with USB and Bluetooth HID devices on Linux, Mac, and Windows.","archived":false,"fork":false,"pushed_at":"2023-10-16T19:06:36.000Z","size":14775,"stargazers_count":2497,"open_issues_count":246,"forks_count":904,"subscribers_count":133,"default_branch":"master","last_synced_at":"2025-04-13T19:39:32.896Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.signal11.us/oss/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/signal11.png","metadata":{"files":{"readme":"README.txt","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}},"created_at":"2010-04-11T20:04:33.000Z","updated_at":"2025-04-07T15:16:46.000Z","dependencies_parsed_at":"2022-08-10T02:06:53.785Z","dependency_job_id":"0c6715b2-f15d-43e2-85d0-c6c3b9a00d22","html_url":"https://github.com/signal11/hidapi","commit_stats":{"total_commits":336,"total_committers":42,"mean_commits":8.0,"dds":"0.34226190476190477","last_synced_commit":"a6a622ffb680c55da0de787ff93b80280498330f"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/signal11%2Fhidapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/signal11%2Fhidapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/signal11%2Fhidapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/signal11%2Fhidapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/signal11","download_url":"https://codeload.github.com/signal11/hidapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235701,"owners_count":22036964,"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":[],"created_at":"2024-08-01T13:00:49.942Z","updated_at":"2025-05-14T22:09:45.326Z","avatar_url":"https://github.com/signal11.png","language":"C","readme":"         HIDAPI library for Windows, Linux, FreeBSD and Mac OS X\n        =========================================================\n\nAbout\n======\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 Mac\nOS X.  HIDAPI can be either built as a shared library (.so or .dll) or\ncan be embedded directly into a target application by adding a single source\nfile (per platform) and a single header.\n\nHIDAPI has four back-ends:\n\t* Windows (using hid.dll)\n\t* Linux/hidraw (using the Kernel's hidraw driver)\n\t* Linux/libusb (using libusb-1.0)\n\t* FreeBSD (using libusb-1.0)\n\t* Mac (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.\n\nLinux/hidraw (linux/hid.c):\nThis back-end uses the hidraw interface in the Linux kernel.  While this\nback-end will support both USB and Bluetooth, it has some limitations on\nkernels prior to 2.6.39, including the inability to send or receive feature\nreports.  In addition, it will only communicate with devices which have\nhidraw nodes associated with them.  Keyboards, mice, and some other devices\nwhich are blacklisted from having hidraw nodes will not work. Fortunately,\nfor nearly all the uses of hidraw, this is not a problem.\n\nLinux/FreeBSD/libusb (libusb/hid.c):\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\nHIDAPI also comes with a Test GUI. The Test GUI is cross-platform and uses\nFox Toolkit (http://www.fox-toolkit.org).  It will build on every platform\nwhich HIDAPI supports.  Since it relies on a 3rd party library, building it\nis optional but recommended because it is so useful when debugging hardware.\n\nWhat Does the API Look Like?\n=============================\nThe API provides the 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#ifdef WIN32\n#include \u003cwindows.h\u003e\n#endif\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n#include \"hidapi.h\"\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\n\t// Read the Manufacturer String\n\tres = hid_get_manufacturer_string(handle, wstr, MAX_STR);\n\twprintf(L\"Manufacturer String: %s\\n\", wstr);\n\n\t// Read the Product String\n\tres = hid_get_product_string(handle, wstr, MAX_STR);\n\twprintf(L\"Product String: %s\\n\", wstr);\n\n\t// Read the Serial Number String\n\tres = hid_get_serial_number_string(handle, wstr, MAX_STR);\n\twprintf(L\"Serial Number String: (%d) %s\\n\", wstr[0], wstr);\n\n\t// Read Indexed String 1\n\tres = hid_get_indexed_string(handle, 1, wstr, MAX_STR);\n\twprintf(L\"Indexed String 1: %s\\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// Finalize the hidapi library\n\tres = hid_exit();\n\n\treturn 0;\n}\n\nIf you have your own simple test programs which communicate with standard\nhardware development boards (such as those from Microchip, TI, Atmel,\nFreeScale and others), please consider sending me something like the above\nfor inclusion into the HIDAPI source.  This will help others who have the\nsame hardware as you do.\n\nLicense\n========\nHIDAPI may be used by one of three licenses as outlined in LICENSE.txt.\n\nDownload\n=========\nHIDAPI can be downloaded from github\n\tgit clone git://github.com/signal11/hidapi.git\n\nBuild Instructions\n===================\n\nThis section is long. Don't be put off by this. It's not long because it's\ncomplicated to build HIDAPI; it's quite the opposite.  This section is long\nbecause of the flexibility of HIDAPI and the large number of ways in which\nit can be built and used.  You will likely pick a single build method.\n\nHIDAPI can be built in several different ways. If you elect to build a\nshared library, you will need to build it from the HIDAPI source\ndistribution.  If you choose instead to embed HIDAPI directly into your\napplication, you can skip the building and look at the provided platform\nMakefiles for guidance.  These platform Makefiles are located in linux/\nlibusb/ mac/ and windows/ and are called Makefile-manual.  In addition,\nVisual Studio projects are provided.  Even if you're going to embed HIDAPI\ninto your project, it is still beneficial to build the example programs.\n\n\nPrerequisites:\n---------------\n\n\tLinux:\n\t-------\n\tOn Linux, you will need to install development packages for libudev,\n\tlibusb and optionally Fox-toolkit (for the test GUI). On\n\tDebian/Ubuntu systems these can be installed by running:\n\t    sudo apt-get install libudev-dev libusb-1.0-0-dev libfox-1.6-dev\n\n\tIf you downloaded the source directly from the git repository (using\n\tgit clone), you'll need Autotools:\n\t    sudo apt-get install autotools-dev autoconf automake libtool\n\n\tFreeBSD:\n\t---------\n\tOn FreeBSD you will need to install GNU make, libiconv, and\n\toptionally Fox-Toolkit (for the test GUI). This is done by running\n\tthe following:\n\t    pkg_add -r gmake libiconv fox16\n\n\tIf you downloaded the source directly from the git repository (using\n\tgit clone), you'll need Autotools:\n\t    pkg_add -r autotools\n\n\tMac:\n\t-----\n\tOn Mac, you will need to install Fox-Toolkit if you wish to build\n\tthe Test GUI. There are two ways to do this, and each has a slight\n\tcomplication. Which method you use depends on your use case.\n\n\tIf you wish to build the Test GUI just for your own testing on your\n\town computer, then the easiest method is to install Fox-Toolkit\n\tusing ports:\n\t\tsudo port install fox\n\n\tIf you wish to build the TestGUI app bundle to redistribute to\n\tothers, you will need to install Fox-toolkit from source.  This is\n\tbecause the version of fox that gets installed using ports uses the\n\tports X11 libraries which are not compatible with the Apple X11\n\tlibraries.  If you install Fox with ports and then try to distribute\n\tyour built app bundle, it will simply fail to run on other systems.\n\tTo install Fox-Toolkit manually, download the source package from\n\thttp://www.fox-toolkit.org, extract it, and run the following from\n\twithin the extracted source:\n\t\t./configure \u0026\u0026 make \u0026\u0026 make install\n\n\tWindows:\n\t---------\n\tOn Windows, if you want to build the test GUI, you will need to get\n\tthe hidapi-externals.zip package from the download site.  This\n\tcontains pre-built binaries for Fox-toolkit.  Extract\n\thidapi-externals.zip just outside of hidapi, so that\n\thidapi-externals and hidapi are on the same level, as shown:\n\n\t     Parent_Folder\n\t       |\n\t       +hidapi\n\t       +hidapi-externals\n\n\tAgain, this step is not required if you do not wish to build the\n\ttest GUI.\n\n\nBuilding HIDAPI into a shared library on Unix Platforms:\n---------------------------------------------------------\n\nOn Unix-like systems such as Linux, FreeBSD, Mac, and even Windows, using\nMingw or Cygwin, the easiest way to build a standard system-installed shared\nlibrary is to use the GNU Autotools build system.  If you checked out the\nsource from the git repository, run the following:\n\n\t./bootstrap\n\t./configure\n\tmake\n\tmake install     \u003c----- as root, or using sudo\n\nIf you downloaded a source package (ie: if you did not run git clone), you\ncan skip the ./bootstrap step.\n\n./configure can take several arguments which control the build. The two most\nlikely to be used are:\n\t--enable-testgui\n\t\tEnable build of the Test GUI. This requires Fox toolkit to\n\t\tbe installed.  Instructions for installing Fox-Toolkit on\n\t\teach platform are in the Prerequisites section above.\n\n\t--prefix=/usr\n\t\tSpecify where you want the output headers and libraries to\n\t\tbe installed. The example above will put the headers in\n\t\t/usr/include and the binaries in /usr/lib. The default is to\n\t\tinstall into /usr/local which is fine on most systems.\n\nBuilding the manual way on Unix platforms:\n-------------------------------------------\n\nManual Makefiles are provided mostly to give the user and idea what it takes\nto build a program which embeds HIDAPI directly inside of it. These should\nreally be used as examples only. If you want to build a system-wide shared\nlibrary, use the Autotools method described above.\n\n\tTo build HIDAPI using the manual makefiles, change to the directory\n\tof your platform and run make. For example, on Linux run:\n\t\tcd linux/\n\t\tmake -f Makefile-manual\n\n\tTo build the Test GUI using the manual makefiles:\n\t\tcd testgui/\n\t\tmake -f Makefile-manual\n\nBuilding on Windows:\n---------------------\n\nTo build the HIDAPI DLL on Windows using Visual Studio, build the .sln file\nin the windows/ directory.\n\nTo build the Test GUI on windows using Visual Studio, build the .sln file in\nthe testgui/ directory.\n\nTo build HIDAPI using MinGW or Cygwin using Autotools, use the instructions\nin the section titled \"Building HIDAPI into a shared library on Unix\nPlatforms\" above.  Note that building the Test GUI with MinGW or Cygwin will\nrequire the Windows procedure in the Prerequisites section above (ie:\nhidapi-externals.zip).\n\nTo build HIDAPI using MinGW using the Manual Makefiles, see the section\n\"Building the manual way on Unix platforms\" above.\n\nHIDAPI can also be built using the Windows DDK (now also called the Windows\nDriver Kit or WDK). This method was originally required for the HIDAPI build\nbut not anymore. However, some users still prefer this method. It is not as\nwell supported anymore but should still work. Patches are welcome if it does\nnot. To build using the DDK:\n\n   1. Install the Windows Driver Kit (WDK) from Microsoft.\n   2. From the Start menu, in the Windows Driver Kits folder, select Build\n      Environments, then your operating system, then the x86 Free Build\n      Environment (or one that is appropriate for your system).\n   3. From the console, change directory to the windows/ddk_build/ directory,\n      which is part of the HIDAPI distribution.\n   4. Type build.\n   5. You can find the output files (DLL and LIB) in a subdirectory created\n      by the build system which is appropriate for your environment. On\n      Windows XP, this directory is objfre_wxp_x86/i386.\n\nCross Compiling\n================\n\nThis section talks about cross compiling HIDAPI for Linux using autotools.\nThis is useful for using HIDAPI on embedded Linux targets.  These\ninstructions assume the most raw kind of embedded Linux build, where all\nprerequisites will need to be built first.  This process will of course vary\nbased on your embedded Linux build system if you are using one, such as\nOpenEmbedded or Buildroot.\n\nFor the purpose of this section, it will be assumed that the following\nenvironment variables are exported.\n\n\t$ export STAGING=$HOME/out\n\t$ export HOST=arm-linux\n\nSTAGING and HOST can be modified to suit your setup.\n\nPrerequisites\n--------------\n\nNote that the build of libudev is the very basic configuration.\n\nBuild Libusb. From the libusb source directory, run:\n\t./configure --host=$HOST --prefix=$STAGING\n\tmake\n\tmake install\n\nBuild libudev. From the libudev source directory, run:\n\t./configure --disable-gudev --disable-introspection --disable-hwdb \\\n\t\t --host=$HOST --prefix=$STAGING\n\tmake\n\tmake install\n\nBuilding HIDAPI\n----------------\n\nBuild HIDAPI:\n\n\tPKG_CONFIG_DIR= \\\n\tPKG_CONFIG_LIBDIR=$STAGING/lib/pkgconfig:$STAGING/share/pkgconfig \\\n\tPKG_CONFIG_SYSROOT_DIR=$STAGING \\\n\t./configure --host=$HOST --prefix=$STAGING\n\n\nSignal 11 Software - 2010-04-11\n                     2010-07-28\n                     2011-09-10\n                     2012-05-01\n                     2012-07-03\n","funding_links":[],"categories":["C","Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsignal11%2Fhidapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsignal11%2Fhidapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsignal11%2Fhidapi/lists"}