Click here to Skip to main content
13,288,121 members (54,120 online)
Click here to Skip to main content
Add your own
alternative version


219 bookmarked
Posted 22 Mar 2007

A USB HID Component for C#

, 22 Mar 2007
Rate this:
Please Sign up or sign in to vote.
A component to communicate with a USB HID device


This article is about a USB HID component which enables you to communicate with HID devices over USB. There is no default component available for USB at this moment, and this component should provide you with a good starting point when writing your own USB HID enabled applications.

This article provides a sample application as well as the component itself.


The component is based on various sources. A good start for USB in C# is this website. Also the book USB COMPLETE (third edition) by Jan Axelson is a must read for anyone wishing to incorporate USB HID into her/his application.

The component is developed during a project at the Avans Hogeschool in 's-Hertogenbosch, The Netherlands.

Using the Code

In the provided sample application, there is a good demonstration on how to include the component. Moreover, the use of the component is very well demonstrated. The only thing that must be done in your own application is implementing the events.

You'll also have to override the following functions in your form, so that your program is USB aware. In the property box, you'll have to provide a vendor and product id of your USB device in order to detect the correct device.

protected override void OnHandleCreated(EventArgs e)
protected override void WndProc(ref Messagea m)
usb.ParseMessages(ref m);
base.WndProc(ref m); // pass message on to base form

Points of Interest

A mouse is always in use by Windows, and cannot be captured by your own application. This also applies to HID devices in use by other applications.


  • 22nd March, 2007: First version, currently in development

Updates will be posted if there is a need for them.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
Netherlands Netherlands
No Biography provided

You may also be interested in...

Comments and Discussions

Question64bit gets wrong GUID, and bytes not copied? Pin
Member 126652188-Jul-17 17:54
memberMember 126652188-Jul-17 17:54 
QuestionProject_for win 8 64 Pin
Andrew Vatoropin2-Dec-16 4:13
memberAndrew Vatoropin2-Dec-16 4:13 
QuestionNow working Pin
Andrew Vatoropin1-Dec-16 20:29
memberAndrew Vatoropin1-Dec-16 20:29 
AnswerRe: Now working Pin
Andrew Vatoropin1-Dec-16 20:43
memberAndrew Vatoropin1-Dec-16 20:43 
GeneralThis project is very good! Pin
Member 1281094123-Oct-16 18:36
memberMember 1281094123-Oct-16 18:36 
Questionwhen i enter VID and PID i get nothing ... can any one help me? Pin
Member 1216412614-Oct-16 5:32
memberMember 1216412614-Oct-16 5:32 
AnswerRe: when i enter VID and PID i get nothing ... can any one help me? Pin
Member 126652188-Jul-17 17:55
memberMember 126652188-Jul-17 17:55 
QuestionHow to test the Sniffer tools Pin
Member 1200259722-Sep-15 18:45
memberMember 1200259722-Sep-15 18:45 
Question.dll' doesn't contain any UserControl types. Pin
Member 1185447122-Jul-15 3:44
memberMember 1185447122-Jul-15 3:44 
AnswerRe: .dll' doesn't contain any UserControl types. Pin
Enisor Marius27-Aug-15 2:49
memberEnisor Marius27-Aug-15 2:49 
AnswerRe: .dll' doesn't contain any UserControl types. Pin
Andrew Vatoropin1-Dec-16 20:33
memberAndrew Vatoropin1-Dec-16 20:33 
QuestionHow can it detect a HID device while working in a Remote Desktop (by mstsc) Pin
Member 1167099913-May-15 3:57
memberMember 1167099913-May-15 3:57 
QuestionReading from USB device Pin
Member 1084745313-Feb-15 13:03
memberMember 1084745313-Feb-15 13:03 
AnswerRe: Reading from USB device Pin
Member 1084745314-Feb-15 13:12
memberMember 1084745314-Feb-15 13:12 
GeneralRe: Reading from USB device Pin
shailesh_sharma7868-Jul-15 20:53
membershailesh_sharma7868-Jul-15 20:53 
GeneralRe: Reading from USB device Pin
amigoface16-Oct-16 7:19
memberamigoface16-Oct-16 7:19 
QuestionSpecifiedDevice Pin
jeremystein123414-Jan-15 11:27
memberjeremystein123414-Jan-15 11:27 
QuestionHow to write data in USB HID device? Pin
Member 112767143-Dec-14 20:46
memberMember 112767143-Dec-14 20:46 
QuestionHow to support more than one device with similar PID and VID and different serial Pin
elekgeek1-Dec-14 21:36
memberelekgeek1-Dec-14 21:36 
QuestionSerial Number of HID device Pin
elekgeek30-Nov-14 1:03
memberelekgeek30-Nov-14 1:03 
AnswerRe: Serial Number of HID device Pin
Garth J Lancaster30-Nov-14 1:31
memberGarth J Lancaster30-Nov-14 1:31 
GeneralRe: Serial Number of HID device Pin
elekgeek30-Nov-14 4:10
memberelekgeek30-Nov-14 4:10 
GeneralRe: Serial Number of HID device Pin
Garth J Lancaster30-Nov-14 11:09
memberGarth J Lancaster30-Nov-14 11:09 
GeneralRe: Serial Number of HID device Pin
elekgeek30-Nov-14 21:20
memberelekgeek30-Nov-14 21:20 
GeneralRe: Serial Number of HID device Pin
Garth J Lancaster1-Dec-14 18:24
memberGarth J Lancaster1-Dec-14 18:24 
Questionerror or not? Pin
igorlisin10-Nov-14 3:54
memberigorlisin10-Nov-14 3:54 
QuestionI can not accept data Pin
Member 111120597-Nov-14 1:11
memberMember 111120597-Nov-14 1:11 
Questionthank you!! Pin
chuck in st paul23-Oct-14 5:02
memberchuck in st paul23-Oct-14 5:02 
QuestionAn unhandled exception of type 'System.IndexOutOfRangeException' occurred in UsbLibrary.dll Pin
Member 1111054828-Sep-14 13:07
memberMember 1111054828-Sep-14 13:07 
QuestionGreat work, but I'm having some trouble, could someone help me? Pin
Member 1104119625-Sep-14 4:36
memberMember 1104119625-Sep-14 4:36 
AnswerRe: Great work, but I'm having some trouble, could someone help me? Pin
Member 861492327-Oct-14 11:20
memberMember 861492327-Oct-14 11:20 
QuestionGreat work! Pin
newtonsrl31-Aug-14 6:18
membernewtonsrl31-Aug-14 6:18 
Questionhow to send input on in-endpoint? Pin
jeffery c7-May-14 18:11
memberjeffery c7-May-14 18:11 
QuestionHow catch event from ConsoleApplication? Pin
Member 1062141925-Feb-14 5:08
memberMember 1062141925-Feb-14 5:08 
QuestionHow to connect USB HID device which doesn't have Product ID and Manufacture ID Pin
avisatna2-Feb-14 22:10
memberavisatna2-Feb-14 22:10 
GeneralMy vote of 3 Pin
Mic8-Aug-13 14:45
memberMic8-Aug-13 14:45 
QuestionUsbLibrary in WPF application Pin
hassan azizi4-Aug-13 21:01
memberhassan azizi4-Aug-13 21:01 
AnswerRe: UsbLibrary in WPF application Pin
candude11-Apr-14 6:14
membercandude11-Apr-14 6:14 
QuestionLocking the USB Barcode Scanner Input Pin
Pasan Indeewara2-Jun-13 20:29
memberPasan Indeewara2-Jun-13 20:29 
QuestionUsbLibrary.UsbHidPort Pin
kainraz27-May-13 8:57
memberkainraz27-May-13 8:57 
GeneralMy vote of 5 Pin
Wolf_124-Apr-13 20:50
memberWolf_124-Apr-13 20:50 
Questionuse your application can't send data to HID device,how to solve? Pin
xuyunhai16-Apr-13 22:58
memberxuyunhai16-Apr-13 22:58 
AnswerRe: use your application can't send data to HID device,how to solve? Pin
Member 1070322424-Sep-14 0:16
memberMember 1070322424-Sep-14 0:16 
QuestionDoes anybody know how to disconnect from the SpecifiedDevice? Pin
MozgC20-Jan-13 4:39
memberMozgC20-Jan-13 4:39 
AnswerRe: Does anybody know how to disconnect from the SpecifiedDevice? Pin
showwei200410-Apr-13 19:45
membershowwei200410-Apr-13 19:45 
Questionproblem with reference in usb hid component for c hsrp . what is the possible solution of this kind of warning. plz help Pin
sefat_23571121-Dec-12 10:52
membersefat_23571121-Dec-12 10:52 
QuestionDataRecievedEventHandler Pin
Member 967835411-Dec-12 23:33
memberMember 967835411-Dec-12 23:33 
Questionmore than a device with same vid&pid? Pin
minkiaprof2-Nov-12 8:00
memberminkiaprof2-Nov-12 8:00 
I need to communicate with a device, called "the master", to read data used to initialize a device (let's say, the "slave"). the devices have same vid&pid. how can I perform this with your library?
thanks a lot in advance
QuestionC# - How to get the FriendlyName from USB Serial Port? Pin
silvio pontes29-Aug-12 19:24
membersilvio pontes29-Aug-12 19:24 
QuestionUse the component twice Pin
beattiet999-Aug-12 18:57
memberbeattiet999-Aug-12 18:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 22 Mar 2007
Article Copyright 2007 by wimar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid