PDA

View Full Version : teensy 3 - Support for any consumer key



gregersrygg
01-06-2014, 12:23 PM
The implementation in Teensy 3 (and previous) only supports 8 hard-coded consumer-keys, so it was not possible to send the key AC_HOME (0x223) or any of the other 660 consumer-keys. I need some of these consumer-keys to create a custom button-panel for my in-car Nexus 7. The home-button, back-button and many other Android functions can only be triggered by consumer-keys (reference http://source.android.com/devices/tech/input/keyboard-devices.html). Some of them are two bytes, so I found it was not sufficient to just modify the keyboard report descriptor.

I changed the keyboard report descriptor to use an array for the consumer-keys. Not sure if that's Correct™, but that's what I got working. Since some of the consumer page usage ids consists of 2 bytes, I also had to steal one byte from the 6 “normal” keyboard keys (now 5). It's also only possible to send one consumer key at the time. Not sure if there are enough available bytes in the packet to add more consumer-keys, or if it's better to add a new HID config for Consumer Keyboard?

Since set_media was only for media-related keys, I added a new method; set_consumer that can take a 16-bit int. Changed the media-key constants in keylayouts.h to the usage id, and set_media now just calls set_consumer.

Tested many different consumer keys on Android 4.2, and they work perfectly. Only tested the volume-keys on OS X 10.9.1, and they work as well. Tried to test on Windows in VirtualBox, but it wouldn't allow me to use the Teensy USB keyboard :(

This patch makes it easier to send any of the consumer-keys without changing the C-library-code for teensy. Sorry about the README.md file in the patch, it's for people stumbling into my GitHub clone.
https://github.com/gregersrygg/teensyduino-android-keyboard/pull/1.patch

Btw: Have you considered putting the Teensy source-code on Gitorious/GitHub or similar? I think that would make it easier for others to contribute to the project :)

Thanks,
Gregers

Nantonos
01-07-2014, 04:58 PM
Interesting, its good to see some support for the 0x0C USB Consumer Page. Besides the Android documentation, you should look at chapter 15 of the HID Usage Tables,
http://www.usb.org/developers/devclass_docs/Hut1_12v2.pdf
linked from here
http://www.usb.org/developers/hidpage/

The Teensy core code is on GitHub:
https://github.com/PaulStoffregen/cores

gregersrygg
01-08-2014, 09:19 AM
Besides the Android documentation, you should look at chapter 15 of the HID Usage Tables,
http://www.usb.org/developers/devclass_docs/Hut1_12v2.pdf


Yes, have spent many hours reading both 1.11 and 1.12 version of the HID spec ;)


The Teensy core code is on GitHub:
https://github.com/PaulStoffregen/cores

Oh, nice! Couldn't find it when searching on GitHub... Will move the pull-request there.

PaulStoffregen
01-08-2014, 09:30 AM
This really needs to be added as a separate interface (and a unique endpoint) with its own report descriptor.

Nantonos
01-08-2014, 11:12 AM
Agreed. Although a keyboard+consumer pairing would be commonly used in practice, that is a combination of two separate interfaces (in the same way as keyboard+mouse+joystick combines three, for example).

Paul
04-12-2016, 12:02 AM
If anyone's still watching this old thread, new & improved media key support is available.

https://forum.pjrc.com/threads/34074-Keyboard-Media-Keys-now-%28hopefully%29-Windows-compatible

I'm closing this old thread. Please comment on the new thread.