dchurch24
Posts: 70
Joined: Thu Dec 06, 2012 7:29 pm

RPi Zero as USB HID device.

Wed Aug 14, 2019 9:05 am

Hi all,

I've been googling a lot and found a fair few pages where a Pi Zero is being used as a USB device (many thanks to people here who pointed me in the right direction).
I've got mine up and running; I have 6 footswitches and they now send a keystroke to a USB connected PC. I now need to send the ALT and SHIFT keys, and am really struggling to wrap my head around the USB report descriptor.

Some of the examples send 32 (hex 20) as the SHIFT button, but the USB HID table (and as far as I can work out as an 8-bit byte) says it should be 225 (hex E1).

I've been following this example: https://www.rmedgar.com/blog/using-rpi- ... descriptor

I realise it's not completely Pi related, but I'm completely lost at this stage and not sure where else to ask.

Would someone be kind enough to talk me through how the descriptor works and how I would arrive at the correct char to send for the "left alt" key for example?

Andyroo

Re: RPi Zero as USB HID device.

Wed Aug 14, 2019 10:41 am

Have a look at page 59 of https://www.usb.org/sites/default/files ... 1_12v2.pdf for control keys in general.

The docs a bit old but I think is still valid.

dchurch24
Posts: 70
Joined: Thu Dec 06, 2012 7:29 pm

Re: RPi Zero as USB HID device.

Wed Aug 14, 2019 10:45 am

Cheers. I just got worked it out.

| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1
|Right Meta | Right Alt | Right Shift | Right Control | Left Meta | Left Alt | Left Shift | Left Control

[modifier key][reserved][key][key][key][key][key][key]

e.g.:
shift - S
32 + 0 + 22 + 0 + 0 + 0 + 0 + 0
chr(32) + NULL_CHR + chr(22) + NULL_CHAR*5 (send the next 5 empty - we only want one key)


It was the 8 bytes for modifier keys that was confusing me. I hadn't realised that that byte gets sent first after being worked out from the set-in-stone sequence of modifier keys.

Return to “Other projects”