{"id":34755336,"url":"https://github.com/andyrozman/hid4java-j15","last_synced_at":"2026-05-25T06:04:09.271Z","repository":{"id":89961242,"uuid":"42991093","full_name":"andyrozman/hid4java-j15","owner":"andyrozman","description":"hid4java (Java 1.5) for of 0.3.1","archived":false,"fork":false,"pushed_at":"2015-09-23T16:30:55.000Z","size":256,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-24T06:35:19.690Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andyrozman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-23T09:21:05.000Z","updated_at":"2020-08-03T02:38:13.000Z","dependencies_parsed_at":"2023-03-02T22:45:44.796Z","dependency_job_id":null,"html_url":"https://github.com/andyrozman/hid4java-j15","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/andyrozman/hid4java-j15","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyrozman%2Fhid4java-j15","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyrozman%2Fhid4java-j15/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyrozman%2Fhid4java-j15/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyrozman%2Fhid4java-j15/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andyrozman","download_url":"https://codeload.github.com/andyrozman/hid4java-j15/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andyrozman%2Fhid4java-j15/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33462501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T02:24:28.008Z","status":"ssl_error","status_checked_at":"2026-05-25T02:23:23.339Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2025-12-25T05:30:45.582Z","updated_at":"2026-05-25T06:04:09.265Z","avatar_url":"https://github.com/andyrozman.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Fork status\n\nProject was forked from 0.3.1 version and it maintains this version, with change to JNA dependency (modified 0.4.1 is\nused).\n\n\n### Project status\n\nRelease: Available for production work\n\nLatest release: 0.3.1 (Java 1.5)\n\n### Summary \n\nThe hid4java project supports USB HID devices through a common API which is provided here under the MIT license.\nThe API is very simple but provides great flexibility such as support for feature reports and blocking reads with\ntimeouts. Attach/detach events are provided to allow applications to respond instantly to device availability.\n\nThe wiki provides a [guide to building the project](https://github.com/gary-rowe/hid4java/wiki/How-to-build-the-project).\n\n### Technologies\n\n* [hidapi](https://github.com/signal11/hidapi) - Native USB HID library for multiple platforms\n* [JNA](https://github.com/twall/jna) - to remove the need for Java Native Interface (JNI) and greatly simplify the project\n* Java 6+ - to remove dependencies on JVMs that have reached end of life\n\n### Maven dependency\n\nI've not gotten around to putting this into Maven Central (it's on my list) so as an interim measure please use the following\nconfiguration in your projects:\n```xml\n\u003crepositories\u003e\n\n  \u003crepository\u003e\n    \u003cid\u003embhd-maven-release\u003c/id\u003e\n    \u003curl\u003ehttps://raw.github.com/bitcoin-solutions/mbhd-maven/master/releases\u003c/url\u003e\n    \u003creleases/\u003e\n  \u003c/repository\u003e\n\n  \u003c!-- Only include the snapshot repo if you're working with the latest hid4java on develop --\u003e\n  \u003crepository\u003e\n    \u003cid\u003embhd-maven-snapshot\u003c/id\u003e\n    \u003curl\u003ehttps://raw.github.com/bitcoin-solutions/mbhd-maven/master/snapshots\u003c/url\u003e\n    \u003c!-- These artifacts change frequently during development iterations --\u003e\n    \u003csnapshots\u003e\n      \u003cupdatePolicy\u003ealways\u003c/updatePolicy\u003e\n    \u003c/snapshots\u003e\n  \u003c/repository\u003e\n\n\u003c/repositories\u003e\n\n\u003cdependencies\u003e\n\n  \u003c!-- hid4java for cross-platform HID USB --\u003e\n  \u003cdependency\u003e\n    \u003cgroupId\u003eorg.hid4java\u003c/groupId\u003e\n    \u003cartifactId\u003ehid4java\u003c/artifactId\u003e\n    \u003cversion\u003e0.4.0\u003c/version\u003e\n  \u003c/dependency\u003e\n\n\u003c/dependencies\u003e\n\n```\n\n### Code example\n\nTaken from [UsbHidTrezorV1Example](https://github.com/gary-rowe/hid4java/blob/develop/src/main/java/UsbHidTrezorV1Example.java) which\nprovides more details. See later for how to run it from the command line.\n\n```java\n// Get HID services\nhidServices = HidManager.getHidServices();\nhidServices.addHidServicesListener(this);\n\n// Provide a list of attached devices\nfor (HidDevice hidDevice : hidServices.getAttachedHidDevices()) {\n  System.out.println(hidDevice);\n}\n\n// Open a Bitcoin Trezor device by Vendor ID and Product ID with wildcard serial number\nHidDevice trezor = hidServices.getHidDevice(0x534c, 0x01, null);\n\n// Send the Initialise message\nbyte[] message = new byte[64];\nmessage[0] = 0x3f;\nmessage[1] = 0x23;\nmessage[2] = 0x23;\n\nint val = trezor.write(message, 64, (byte) 0);\nif (val != -1) {\n  System.out.println(\"\u003e [\" + val + \"]\");\n} else {\n  System.err.println(trezor.getLastErrorMessage());\n}\n    \n```\n \n### Getting started\n\nIf you're unfamiliar with Maven and git the wiki provides [an easy guide to creating a development environment](https://github.com/gary-rowe/hid4java/wiki/How-to-build-the-project).\n\nThe project uses the standard Maven build process and can be used without having external hardware attached. Just do the usual\n\n```\ncd \u003cproject directory\u003e\nmvn clean install\n```\n\nand you're good to go. Your next step is to explore the examples (e.g. `UsbHidTrezorV1Example`). From the command line:\n\n```\nmvn clean compile exec:java -Dexec.mainClass=\"UsbHidTrezorV1Example\"\n```\nIf you have a Trezor device attached you'll see a \"Features\" message appear as a big block of hex otherwise it will be\njust a simple enumeration of attached USB devices. You can plug various devices in and out to see messages.\n\nUse CTRL+C to quit the example.\n\n### Frequently asked questions (FAQ)\n\n#### What platforms do you support ?\n\nIf you have a native version of `hidapi` for your platform then you'll be able to support it. \n\nPre-compiled versions for Windows (32/64), OS X (10.5+) and Linux (32/64) are provided and you\nmust follow the JNA naming convention when adding new libraries.\n\n#### Why not just use usb4java ?\n\nThe [usb4java](http://usb4java.org/) project, while superb, does not support HID devices on OS X \nand apparently there are no plans to introduce HID support anytime soon.\n \nYou will find that trying to claim the USB device on OS X will fail with permissions problems. If\nyou apply a workaround (such as adding a kernel extension) then it will still fall over just a\nlittle later in the process. The bottom line is that you *must* use hidapi to communicate with HID\ndevices on OS X.\n\n#### Is this going into Maven Central ?\n\nYes. There's a bit of general tidying work left to do to take it to a first release but when that's \ndone it will be uploaded to Maven Central. \n \n#### Can I just copy this code into my project ?\n\nYes. Perhaps you'd prefer to use \n\n```\ngit submodule add https://github.com/gary-rowe/hid4java hid4java \n```\nso that you can keep up to date with changes whilst still fixing the version. \n\n\n### Troubleshooting\n\nThe following are known issues and their solutions or workarounds.\n\n#### I get a `SIGSEGV (0xb)` when starting up\n\nThis shouldn't occur unless you've been changing the code. \nYou have probably got the `getFieldOrder` list wrong. Use the field list from Class.getFields() to get a suitable order.\nAnother cause is if a `Structure` has not been initialised and is being deferenced, perhaps in a `toString()` method.\n\n#### I get a \"The parameter is incorrect\" when writing\n\nThere is a special case on Windows for report ID `0x00` which can cause a misalignment during a hidapi `write()`.\nTo compensate for this, hid4java will detect when it is running on Windows with a report ID of `0x00` and simply copy\nthe `data` unmodified to the write buffer. In all other cases it will prepend the report ID to the data before submitting\nit to hidapi.\n\nIf you're seeing this then it may be that your code is attempting to second guess hid4java.\n\n#### The hidapi library doesn't load\n\nOn startup hid4java will search the classpath looking for a library that matches the machine OS and architecture (e.g. Windows running on AMD64). It uses the JNA naming conventions to do this and will report the expected path if it fails. You can add your own entry under `src/main/resources` and it should get picked up. Ideally you should [raise an issue](https://github.com/gary-rowe/hid4java/issues) on the hid4java repo so that the proper library can be put into the project so that others can avoid this problem.\n\n#### The hidapi library loads but takes a long time on Windows\n\nYou have probably terminated the JVM using a `kill -9` rather than a clean shutdown. This will have left the `HidApi` process lock on the DLL still in force and Windows will continuously check to see if it can share it with a new instance.\nJust detach and re-attach the device to clear it.\n\n#### I'm seeing spurious attach/detach events occurring on Windows\n\nThis was a device enumeration bug in early versions of hid4java. Use 0.3.1 or higher.\n\n#### My device doesn't work on Linux\n\nDifferent flavours of Linux require different settings:\n\n##### Ubuntu\nOut of the box Ubuntu classifies HID devices as belonging to root. You can override this rule by creating your own under `/etc/udev/rules.d`:\n```\nsudo gedit /etc/udev/rules.d/99-myhid.rules\n```\nMake the content of this file as below (using your own discovered hex values for `idProduct` and `idVendor`):\n```\n# My HID device\nATTRS{idProduct}==\"0001\", ATTRS{idVendor}==\"abcd\", MODE=\"0660\", GROUP=\"plugdev\"\n```\nSave and exit from root, then unplug and replug your device. The rules should take effect immediately. If they're still not running it may that you're not a member of the `plugdev` group. You can fix this as follows (assuming that `plugdev` is not present on your system):\n```\nsudo addgroup plugdev\nsudo addgroup yourusername plugdev\n```\n\n##### Slackware\nEdit the USB udev rules `/etc/udev/rules.d` as follows:\n```\nMODE=\"0666\", GROUP=\"dialout\"\n```\n\n##### ARM\nRunning on ARM machines you may encounter problems due to a missing library. This is just a naming issue for the `udev` library and can be resolved using the following command (or equivalent for your system):\n```\nsudo ln -sf /lib/arm-linux-gnueabihf/libudev.so.1 /lib/arm-linux-gnueabihf/libudev.so.0\n```\nThanks to @MaxRoma for that one!\n\n#### My device doesn't work on Windows\n\nCheck that the usage page is not `0x06` which is reserved for keyboards and mice. [Windows opens these devices for its exclusive use](https://msdn.microsoft.com/en-us/library/windows/hardware/jj128406%28v=vs.85%29.aspx) and thus hid4java\ncannot establish its own connection to them. You will need to use the lower level usb4java library for this.\n\n### Closing notes\n\nAll trademarks and copyrights are acknowledged.\n\nMany thanks to victorix who provided the basis for this library. Please see the inspiration \u003ca href=\"http://developer.mbed.org/cookbook/USBHID-bindings-\"\u003eon the mbed.org site.\u003c/a\u003e\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyrozman%2Fhid4java-j15","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandyrozman%2Fhid4java-j15","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandyrozman%2Fhid4java-j15/lists"}