Click here to Skip to main content
Click here to Skip to main content

A USB HID Component for C#

, 22 Mar 2007 CPOL
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

Comments and Discussions

QuestionI can not accept data PinmemberMember 111120597-Nov-14 1:11 
Questionthank you!! Pinmemberchuck in st paul23-Oct-14 5:02 
QuestionAn unhandled exception of type 'System.IndexOutOfRangeException' occurred in UsbLibrary.dll PinmemberMember 1111054828-Sep-14 13:07 
QuestionGreat work, but I'm having some trouble, could someone help me? PinmemberMember 1104119625-Sep-14 4:36 
AnswerRe: Great work, but I'm having some trouble, could someone help me? PinmemberMember 861492327-Oct-14 11:20 
QuestionGreat work! Pinmembernewtonsrl31-Aug-14 6:18 
Questionhow to send input on in-endpoint? Pinmemberjeffery c7-May-14 18:11 
QuestionHow catch event from ConsoleApplication? PinmemberMember 1062141925-Feb-14 5:08 
QuestionHow to connect USB HID device which doesn't have Product ID and Manufacture ID Pinmemberavisatna2-Feb-14 22:10 
GeneralMy vote of 3 PinmemberMic8-Aug-13 14:45 
QuestionUsbLibrary in WPF application Pinmemberhassan azizi4-Aug-13 21:01 
AnswerRe: UsbLibrary in WPF application Pinmembercandude11-Apr-14 6:14 
QuestionLocking the USB Barcode Scanner Input PinmemberPasan Indeewara2-Jun-13 20:29 
QuestionUsbLibrary.UsbHidPort Pinmemberkainraz27-May-13 8:57 
GeneralMy vote of 5 PinmemberWolf_124-Apr-13 20:50 
Questionuse your application can't send data to HID device,how to solve? Pinmemberxuyunhai16-Apr-13 22:58 
AnswerRe: use your application can't send data to HID device,how to solve? PinmemberMember 1070322424-Sep-14 0:16 
QuestionDoes anybody know how to disconnect from the SpecifiedDevice? PinmemberMozgC20-Jan-13 4:39 
AnswerRe: Does anybody know how to disconnect from the SpecifiedDevice? Pinmembershowwei200410-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 Pinmembersefat_23571121-Dec-12 10:52 
QuestionDataRecievedEventHandler PinmemberMember 967835411-Dec-12 23:33 
Questionmore than a device with same vid&pid? Pinmemberminkiaprof2-Nov-12 8:00 
QuestionC# - How to get the FriendlyName from USB Serial Port? Pinmembersilvio pontes29-Aug-12 19:24 
QuestionUse the component twice Pinmemberbeattiet999-Aug-12 18:57 
AnswerRe: Use the component twice Pinmemberbeattiet999-Aug-12 20:02 

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

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

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