Even though the device is connected to an usb port the communication is done through a (virtual) serial port. The protocol specification is available in the developer section on Art.Lebedev Studio's website. There's also some c sample code available which proved to be very useful to build this class. The document lists the following commands to send data to the device:

  • Switch the device on and off
  • Send image data for a specific key
  • Show sent image for a specific key
  • Change the brightness
There're two additional commands available, to read and write the internal id of the device. We're not going to use them for this article. They could be used if you've multiple devices connected to differentiate them.

All the commands we're sending have a length of 197 bytes, the last byte being the checksum. The response to a command consists of two bytes: a 0 to tell us this is a command confirmation and as second byte the checksum. Ideally that checksum matches the one of the sent command - if not the data was somehow corrupted and we've to send it again.

And the device is not just waiting until we send it something, it will also send something to us: the keys which are currently pressed - of course, wouldn't qualify as keyboard otherwise. These messages are also 2 bytes long, first byte being a 1 and the second byte is the 1-based index of the pressed key. We can get them anytime and very often - as long as one or more keys are pressed they're repeatedly send. When commands are send at the same time we get a mix of key messages and command confirmations.