I'm using RPI Zero W as keyboard gadget. It's supposed to act as keyboard getaway from Bluetooth keyboard to USB keyboard. I'm running "showkey" shell command process giving me codes of just pressed keys.

I can get pressed key codes in one of the flowing ways:

# showkey -k // press "a" key keycode 30 press keycode 30 release


# showkey -s // press "a" key 0x1e 0x9e

As a final result to send to /dev/hidg0 I need to form a 8-byte HID packet. For the "a" key press it looks like "\0\0\x4\0\0\0\0\0".

Could you please advice how such "showkey" codes can be converted into such binary(?) HID packet? My attempts so convert values between HEX, DEC, ASCII, and Binary, are all failed.

I'm dealing with PHP script, so ideally, I would prefer to do just something like file_put_contents('/dev/hidg0', "\0\0\x4\0\0\0\0\0");

or I can send a common shell call:

echo -ne "\0\0\x4\0\0\0\0\0" > /dev/hidg0

UPD: Keyboard is QWERTY.

UPD: PI Zero W has Wifi and Bluetooth. Incoming key codes come from Bluetooth keyboard.

Thanks a lot!


1 Answer 1


The fastest solution appeared to be manual test and compare of all the keys one-by-one.

Not the answer you're looking for? Browse other questions tagged or ask your own question.