1

I am trying to get my pi zero to act as a HID USB keyboard when plugged in to a computer, following this guide.

I finished the configuration, and I get to the "Keyboard / Mouse / Joystick (HID)" section. I added these commands to the bottom of /etc/rc.local:

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

When I plug the pi zero into the target computer, it recognizes the USB device, as shown by dmesg:

[26919.807536] usb 1-1: new high-speed USB device number 48 using xhci_hcd
[26919.828689] usb 1-1: New USB device found, idVendor=1d6b, idProduct=0104
[26919.828698] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[26919.828704] usb 1-1: Product: iSticktoit.net USB Device
[26919.828709] usb 1-1: Manufacturer: Tobias Girstmair
[26919.828713] usb 1-1: SerialNumber: fedcba9876543210
[26919.831132] input: Tobias Girstmair iSticktoit.net USB Device as /devices/pci0000:00/0000:00:15.0/usb1/1-1/1-1:1.0/0003:1D6B:0104.0007/input/input21
[26919.888595] hid-generic 0003:1D6B:0104.0007: input,hidraw1: USB HID v1.01 Keyboard [Tobias Girstmair iSticktoit.net USB Device] on usb-0000:00:15.0-1/input0

But the computer does not receive any keystrokes at all. I am really struggling to figure this out, and I would apreciate any help. Thanks!

eeze
  • 111
  • 4

1 Answers1

2

I don't know if this helps but it reduces one possible source of error. Doing what the developers from systemd suggest is using a Unit file. Here is a very generic one for your problem. Create a new unit file with:

rpi ~$ sudo systemctl edit --force --full hid-keyboard.service

In the empty editor insert these statements, save them and quit the editor:

[Unit]
Description=HID keyboard emulator
After=multi-user.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/bash -c 'echo -ne "\0\0\x4\0\0\0\0\0" > /dev/hidg0'
ExecStart=/bin/bash -c 'echo -ne "\0\0\0\0\0\0\0\0" > /dev/hidg0'

[Install]
WantedBy=multi-user.target

Enable the new service with:

rpi ~$ sudo systemctl enable hid-keyboard.service

On boot/startup/poweron it is executed one time. You can manual restart it and show its status with

rpi ~$ sudo systemctl restart hid-keyboard.service
rpi ~$ sudo systemctl status hid-keyboard.service
Ingo
  • 42,961
  • 20
  • 87
  • 207