# Virtual keyboard using HID gadget

**URL:** <https://discourse.nodered.org/t/virtual-keyboard-using-hid-gadget/47255>\
**Category:** General\
**Created:** [16 June 2021 15:19 UTC](https://discourse.nodered.org/t/virtual-keyboard-using-hid-gadget/47255 "2021-06-16T15:19:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [16 June 2021 15:19 UTC](https://discourse.nodered.org/t/virtual-keyboard-using-hid-gadget/47255/1 "2021-06-16T15:19:17Z")

</div>

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

> **[raspberrypisig/pizero-usb-hid-keyboard](https://github.com/raspberrypisig/pizero-usb-hid-keyboard)**
>
> Fake a raspberry pi zero w to look like a keyboard to a Windows 10 PC - raspberrypisig/pizero-usb-hid-keyboard

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

> <https://github.com/raspberrypisig/pizero-usb-hid-keyboard/blob/master/hid-gadget-test.c>

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:

```auto
# 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)

> **[hut1\_21.pdf](https://usb.org/sites/default/files/hut1_21.pdf)**
>
> 3.61 MB

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [17 June 2021 08:13 UTC](https://discourse.nodered.org/t/virtual-keyboard-using-hid-gadget/47255/2 "2021-06-17T08:13:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [28 June 2021 19:29 UTC](https://discourse.nodered.org/t/virtual-keyboard-using-hid-gadget/47255/3 "2021-06-28T19:29:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 July 2021 19:29 UTC](https://discourse.nodered.org/t/virtual-keyboard-using-hid-gadget/47255/4 "2021-07-12T19:29:36Z")

</div>

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