HidSharp | multiplatform C # library for USB HID devices
kandi X-RAY | HidSharp Summary
kandi X-RAY | HidSharp Summary
HIDSharp is a multiplatform C# library for USB HID devices. Version 2.0 allows you to read and parse reports from any USB HID input device. You can read USB gamepads, scales, anything you need. It does this by providing full report descriptor and report parsing capability. HIDSharp is, to my knowledge, the first driverless cross-platform library which can do this! Of course, raw reading and writing is still fully supported. Version 1.5 and below are COM enabled to allow use by VB6 and MS Access programs (the .NET Framework will of course need to be installed). If there is demand I may add COM support to HIDSharp 2.0. HIDSharp has received eight years of continual use with a Dymo Scale in MS Access, and seven years in commercial software with a wide variety of USB HID devices I've developed, so I know it to be reliable. HIDSharp supports Windows, MacOS, and Linux (hidraw). HIDSharp uses the Apache open-source license. Originally distributed by James F. Bellinger through his webpage. Available as a Nuget package.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of HidSharp
HidSharp Key Features
HidSharp Examples and Code Snippets
Community Discussions
Trending Discussions on HidSharp
QUESTION
I managed to implement the HID device in Unity Input System and I can read from it easily. But how to send data back to the HID device?
This is the IInputDeviceCommandInfo
implementation I have:
ANSWER
Answered 2022-Feb-03 at 16:25Ok, that was not an easy problem to solve:
The problem was that IInputDeviceCommandInfo
does not force user to implement Field(0)
to be an InputDeviceCommand
. InputDeviceCommand
must be added at Field(0) offset and other fields must be shifted respectively.
The second problem was that my device required different size of the output data. Probably OS checks if the sizes matches (the one reported by the descriptor in capabilities.outputReportSize
and the one actually to be sent).
So I have added missing fields in the struct and it works:
QUESTION
I have a wireless USB remote control that I purchased on amazon that I would like to use to trigger actions in my program.
When connected in Linux the remote shows up as a separate keyboard and mouse. So, I'm looking for a way in c# to intercept the keyboard events from the remote and use them in my application.
Some options I've considered...
Option 1 - Read file in /dev/input/by-id
Inside this folder, there is a file called "usb-SG.Ltd_SG_Control_Mic-if03-mouse" which, when I tail it does produce some information.
This is not ideal for two reasons:
- It requires elevated privileges to access the data
- It doesn't allow my program exclusive access to the input data
Option 2 - Using HIDSharp
https://www.zer7.com/software/hidsharp
This is a library that looks like this can accomplish what I'm looking for, but the documentation is quite sparse.
...ANSWER
Answered 2021-Oct-28 at 14:41Answering my own question here because I had to do a lot of research for it and I'm sure it will help someone else later. I went with option 1 because it seemed to be the easiest to implement.
Warning - There is going to be a lot of code in this post
SummaryFor my intents and purposes, I wanted to have some code that would publish an event any time the user pressed a key anywhere on the system. While developing this, I found that I could also hook into mouse events as well.
It's important to note, that the code here like the linux OS doesn't really distinguish between a keyboard button press and a mouse button press. To linux, they're both just buttons.
Understanding that you can actually expand this code to work with other items like gamepads and special input peripherals if you desire.
Additional Gotchas - As expressed in the question, this code will not block the device input to other programs. This can be problematic if you want to override the default functionality of say the power button or the volume buttons.
Setting Up PermissionsIn order to run this code, the user that runs this program will have to be in the input user group otherwise it will throw an exception. Run this code to add the current user to that group.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install HidSharp
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page