locked
Reading a USB HID device RRS feed

  • Question

  • I have a console device that connects to a USB port via USB-HID and uses the hid.dll driver.   The console device generates keystrokes.

     

    I would like to write a program that reads the keystrokes generated by the console device.

     

    If I write a Windows program that traps WM_KEYDOWN it works fine, but the program must have focus.   So if I can read the usb-hid device directly, the program doesn't need focus.   I have tried trapping the keyboard, but there are latency issues.

     

    Any suggestions?

    Tuesday, June 19, 2007 10:33 PM

Answers

  • The correct was is to grab RAW INPUT from the USB HID device using:

     

    http://msdn2.microsoft.com/en-us/library/ms645543.aspx

     

    as a start.

     

     

    Thursday, June 28, 2007 10:14 PM
  • You can hook keyboard events directly with SetWindowsHookEx and capture low level keyboard events, even if your program does not have focus.

    There is also a way to interact directly with the HID, but I never tried that. The DDK does have some samples, so if you really need to go via HID you could have a look at those samples.

    The DDK is a free download nowadays as part of the KMDF.

    And finally, you could write a keyboard filter driver that is inserted in the device driver stack but I would not go there if you can avoid it. using the windows hook or HID should work.

    Wednesday, June 20, 2007 6:16 AM

All replies

  • You can hook keyboard events directly with SetWindowsHookEx and capture low level keyboard events, even if your program does not have focus.

    There is also a way to interact directly with the HID, but I never tried that. The DDK does have some samples, so if you really need to go via HID you could have a look at those samples.

    The DDK is a free download nowadays as part of the KMDF.

    And finally, you could write a keyboard filter driver that is inserted in the device driver stack but I would not go there if you can avoid it. using the windows hook or HID should work.

    Wednesday, June 20, 2007 6:16 AM
  • For some reason hooking the keyboard is slow.   So I would like to see if I could read the HID USB driver.

     

    There is a refererence in a document on the web (doc7645.pdf - USB PC Driver based on HID Class) to some sample code:

    UsbHidDemoCodeDlg.cpp

     

    but I have no idea where that is.

     

    Wednesday, June 20, 2007 5:08 PM
  • UsbHidDemoCodeDlg.cpp is a file to a dll product from Atmel.

    Wednesday, June 20, 2007 10:12 PM
  • The correct was is to grab RAW INPUT from the USB HID device using:

     

    http://msdn2.microsoft.com/en-us/library/ms645543.aspx

     

    as a start.

     

     

    Thursday, June 28, 2007 10:14 PM

  • This sounds great, but I'm using an older Visual Studio 6 and my winuser.h doesn't include the required structure and function definitions...

    Can someone get me an updated one pls.


    thx, Jo

    Wednesday, November 7, 2007 3:55 PM