PaulStoffregen/cores — pull request #4 by gregersrygg (2014-01-08 09:23:06+00:00)
Title: Support any usage ids from the HID consumer page

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/te...d-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 :( The AC_HOME even works as the home-button on an iPad if using the iPad camera connection kit!