Click here to Skip to main content
12,819,727 members (37,202 online)
Click here to Skip to main content
Add your own
alternative version


218 bookmarked
Posted 22 Mar 2007

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

You may also be interested in...

Comments and Discussions

GeneralUSB/HID Pin
sswcharlie6-Jun-07 14:07
membersswcharlie6-Jun-07 14:07 
GeneralRe: USB/HID Pin
wimar12-Jun-07 23:02
memberwimar12-Jun-07 23:02 
GeneralRe: USB/HID Pin
sswcharlie9-Aug-07 17:06
membersswcharlie9-Aug-07 17:06 
QuestionMultiple identical devices? Pin
antmason29-May-07 5:59
memberantmason29-May-07 5:59 
AnswerRe: Multiple identical devices? Pin
wimar30-May-07 1:09
memberwimar30-May-07 1:09 
Generalcommunicating other than HID Pin
ardaarda15-May-07 23:10
memberardaarda15-May-07 23:10 
GeneralRe: communicating other than HID Pin
wimar16-May-07 6:50
memberwimar16-May-07 6:50 
QuestionA problem is observed Pin
s_stavrev24-Apr-07 6:51
members_stavrev24-Apr-07 6:51 
Hello wimar,
thanks for your article. Smile | :)
I had problem running UsbApp. Once it is started on PC with no specified HID device attached and the OK button is pressed than when the device is attached there is no way to detect it any more. only "Found a Device" message appears. The problem stays until the HID driver is uninstalled and re-installed. I'll try to find any workaround but I afraid my skills are not enough yet Blush | :O
For testing your UsbApp I used a USB sound card which is composite device - it has both HID and Audio interfaces. I tried it on two different PCs but the problem ocures on both of them.

QuestionUSB HID Pin
kingdom197713-Apr-07 3:45
memberkingdom197713-Apr-07 3:45 
AnswerRe: USB HID Pin
wimar15-Apr-07 22:41
memberwimar15-Apr-07 22:41 
GeneralRe: USB HID Pin
kinglaws16-Apr-07 8:12
memberkinglaws16-Apr-07 8:12 
GeneralRe: USB HID Pin
wimar17-Apr-07 8:52
memberwimar17-Apr-07 8:52 
GeneralRe: USB HID Pin
kinglaws17-Apr-07 9:39
memberkinglaws17-Apr-07 9:39 
GeneralRe: USB HID Pin
kinglaws19-Apr-07 14:24
memberkinglaws19-Apr-07 14:24 
GeneralRe: USB HID Pin
Iwan Budihalim16-Aug-07 3:21
memberIwan Budihalim16-Aug-07 3:21 
QuestionDetecting a HID Device [modified] Pin
BalaVikram29-Mar-07 0:47
memberBalaVikram29-Mar-07 0:47 
AnswerRe: Detecting a HID Device Pin
wimar29-Mar-07 5:06
memberwimar29-Mar-07 5:06 
GeneralRe: Detecting a HID Device Pin
BalaVikram1-Apr-07 20:49
memberBalaVikram1-Apr-07 20:49 

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.170308.1 | Last Updated 22 Mar 2007
Article Copyright 2007 by wimar
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid