Page 1 of 1

Is it possible to do extra comm with usb-hid keyboard?

Posted: Tue Dec 11, 2012 6:45 am
by fish47
Hello everyone, rencently I got a interesting idea --- making a customizable keyboard, but I came accross some problems I can't figure out. I hope you can help me. Thanks a lot.
As the similar projects which have been done, making a usb-hid keyboard is not a difficult task.
I want to customize the keycodes of the buttons via PC. Using IR or UART is ok, but they aren't so convenient as the previous solution.
Since libusb can do direct communication with usb device, even the device isn't driven. But is it poosible to do so while the device has been recognized as usb-hid keyboard ?

Re: Is it possible to do extra comm with usb-hid keyboard?

Posted: Wed Dec 12, 2012 6:07 pm
by xiangrui
For Windows, it is unlikely. The system will claim full control of the USB HID keyboard. For Linux, I am not sure, but probably you can do it.

-Xiangrui

Re: Is it possible to do extra comm with usb-hid keyboard?

Posted: Thu Dec 13, 2012 9:51 am
by fish47
xiangrui wrote:For Windows, it is unlikely. The system will claim full control of the USB HID keyboard. For Linux, I am not sure, but probably you can do it.

-Xiangrui


Thanks for your tips.

Re: Is it possible to do extra comm with usb-hid keyboard?

Posted: Sun Dec 16, 2012 2:07 pm
by Bob
In Windows, it's possible to send and receive data to a keyboard or mouse using feature reports.
The trick is to open the device as ACCESS_TYPE_NONE otherwise it will fail as it's locked and owned by windows.

handle = CreateFile(deviceDetails->DevicePath, ACCESS_TYPE_NONE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, openFlag, NULL);

Re: Is it possible to do extra comm with usb-hid keyboard?

Posted: Wed Mar 13, 2013 2:59 am
by fish47
I have found a better solution. In short, the way to achieve my goal is to decalre two devices in hid descriptor: one for keyboard/mouse, one for a hid-data device. LibUsb can claim the device(s) even so. It works fine under Linux or Windows platform. If you want more detail, the website below is worth reading.
http://www.frank-zhao.com/cache/hid_tutorial_1.php

Re: Is it possible to do extra comm with usb-hid keyboard?

Posted: Thu Mar 14, 2013 5:31 pm
by Bob
That means you must install libusb drivers on the target.
If you're going to do that, there is no need for a composite device descriptor, libusb can access mice and keyboards without any tricks.
The method I described doesn't require any drivers or libusb to be installed.
However, using libusb means it will pretty much work on any platform which is always a good thing :)

Re: Is it possible to do extra comm with usb-hid keyboard?

Posted: Sun Mar 17, 2013 8:26 am
by fish47
Bob wrote:That means you must install libusb drivers on the target.
If you're going to do that, there is no need for a composite device descriptor, libusb can access mice and keyboards without any tricks.
The method I described doesn't require any drivers or libusb to be installed.
However, using libusb means it will pretty much work on any platform which is always a good thing :)

You can use the public pid/vid that v-usb provides. It can be driven on win7 and ubuntu12.04. According to *libusbx* wiki, keyboard and mouse is not accessible.
https://github.com/libusbx/libusbx/wiki ... kend#about
BTW, using *libusbx* is very convenient, because it provide win32 static/dynamic library dist. You can also compile it on Linux too.

Re: Is it possible to do extra comm with usb-hid keyboard?

Posted: Thu Mar 21, 2013 5:50 pm
by Bob
I haven't tried libusbx but can assure you that the older libusb works fine with keyboards and mice when doing control transfers.

Re: Is it possible to do extra comm with usb-hid keyboard?

Posted: Sun Mar 24, 2013 9:29 pm
by xiangrui
fish47 wrote:I have found a better solution. In short, the way to achieve my goal is to decalre two devices in hid descriptor: one for keyboard/mouse, one for a hid-data device. LibUsb can claim the device(s) even so. It works fine under Linux or Windows platform. If you want more detail, the website below is worth reading.
http://www.frank-zhao.com/cache/hid_tutorial_1.php


I just tried a keyboard and another generic hid device, and it works fine! I had to use reportID for both devices. Thanks for the information.

I wonder whether there is a way to use different VID/PID and device name for the two device, which are all defined in usbconfig.h. According to V-USB, they should have different PID, since they use different drivers.

-Xiangrui