Virtual keyboard using HID gadget

I know this is somewhat out of the realm of node-red but I figured I don't lose anything by asking.

I'm using node-red to send HID (keyboard/mouse) commands to a host device.

I used the project below to enable HID mode on a Pi Zero

Sending any of the keys inside the compiled program below works fine.

However, the program is missing a lot of characters so I went down the route of skipping the program and just sending bytes directly to the device.

To send "Hi" for I can use

Sending the keys for “Hi” looks like this:

# H (Right shift + h)
echo -ne "\x20\0\xb\0\0\0\0\0" > /dev/hidg0
# Release all keys
echo -ne "\0\0\0\0\0\0\0\0" > /dev/hidg0
# i
echo -ne "\0\0\xc\0\0\0\0\0" > /dev/hidg0
# Release all keys
echo -ne "\0\0\0\0\0\0\0\0" > /dev/hidg0

What I don't understand, is why some key usage IDs don't match what's listed in the USB spec (table on page 82)

For example:
the spec states to use 0B for h but I actually need to send xb or the character sent to the host device ends up being wrong

I'd guess that just representation. 0B is one way of writing a hex byte - zero for first 4 bits and b = 1011 (binary) = 11 decimal for next 4 bits.... for your input the way to represent it is xB - x to indicate it's hex and then just the b - no need for the leading 0.

@dceejay Thanks, that seemed to clear up the issue for me.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.