Author Topic: Difference between Keyboard class and HID class for a Keyboard  (Read 8447 times)

Dobaz

  • Member
  • ***
  • Posts: 23
Hi,

I have made a device to play games (joystick) that emulates a keyboard. It uses the HID class and it is a composite device..

It works fine but there is one thing that should behave differently.  

If I press two buttons at the same time it behaves exactly like my laptop keyboard. Let's say I press 6 and hold it and then press 4.  I will see this:
666666666666666666666666664444444444444444444444...   That's fine.

When pressing a key and hold it on my device while doing the same at same time on my laptop keyboard ( both shooting with key press hold).

Here is what I get 464464646464664646464646464664646464646464646646464646464646466464

Both shooting, all mixed up, none of the keyboard takes over.  

I would like to get the same expected result as if only one keyboard was used:
66666666666666666666666644444444444444444444444444

Is it possible?  Most probably because I have another USB keyboard that works as intended. If If press a key on it while doing the same with my laptop's keyboard I got the right thing:
6666666666666666644444444444444444444...  The difference is: It is a Keyboard Class one...


Is it because I am using HID class (composite device) instead of keyboard class?  How can I make make this to work as intended?

Many thanks
« Last Edit: April 11, 2013, 01:27:49 pm by Dobaz »

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Difference between Keyboard class and HID class for a Keyboard
« Reply #1 on: April 11, 2013, 03:33:15 pm »
Windows considers all attached keyboards as one big keyboard so you will see the data from all keyboards.

However "raw input" (do a web search) can select input from a specific keyboard.

Keyboards are HID-class devices whether they are part of a composite device or not.

See the USB HID specification for an example keyboard report descriptor.


Dobaz

  • Member
  • ***
  • Posts: 23
Re: Difference between Keyboard class and HID class for a Keyboard
« Reply #2 on: April 11, 2013, 05:34:13 pm »
Thank you,

I found another USB Keyboard to test.

When pressing a key down and holding it on my laptop's keyboard and on the other keyboards, here is what I get:

- My device and laptop Keyboard:
  64646646464646466446466464646464
-USB Keyboard (first one I talked about in first post):
 6666666666666666664444444444444444444
-USB Keyboard 2 (other one):
646666464646646446646464646466446646464646466464466

Let's forget about my device for now, how come I get different behaviors between the two USB keyboard?

Those are real keyboards not emulated ones...

Thank you

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Difference between Keyboard class and HID class for a Keyboard
« Reply #3 on: April 11, 2013, 06:06:10 pm »
A protocol analyzer would show what is happening on the bus.

With the 6666666666666666664444444444444444444 keyboards, if you keep pressing both, do you ever see the first keyboard's 6s again?

The bottom line is that if you want to read input from a specific keyboard, use raw input.

Dobaz

  • Member
  • ***
  • Posts: 23
Re: Difference between Keyboard class and HID class for a Keyboard
« Reply #4 on: April 11, 2013, 06:28:00 pm »
No, I won't see any other 6 again.

And I want both keyboards input at the same time, it is to play games. I don't need to read it.

What could cause the 2 keyboards (not my device) to act differently? One makes a big keyboard and the other one acts like there's two keyboards.

I will check for a protocol analyser.

Thanks again
« Last Edit: April 11, 2013, 07:31:35 pm by Dobaz »

Dobaz

  • Member
  • ***
  • Posts: 23
Re: Difference between Keyboard class and HID class for a Keyboard
« Reply #5 on: April 22, 2013, 09:18:59 pm »
Hi,

I realize it's already been a few days since I asked for this.  I am still looking for an answer but can't find it anywhere!!

I forgot to mention that I tried the protocol analyzer and found that the device sends exactly the same commands (key press and release) as other USB keyboards so the problem is not about how the keys are sent to Windows.

Anyone has a clue?

Thanks

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Difference between Keyboard class and HID class for a Keyboard
« Reply #6 on: April 22, 2013, 10:41:17 pm »
The HID report descriptors might be different. A hardware protocol analyzer or some software analyzers will show the descriptors during enumeration.