/Raspberry-Zero-Mouse-Simulation

Simulate mouse and keyboard via Raspberry Pi OTG

Primary LanguageShell

Raspberry-Zero-Mouse-Simulation

Simulate mouse and keyboard via Raspberry Pi OTG

There are many tutorials how to simulate keyboard input with the Raspberry Pi zero, but no good how to simulate mouse movement. Here is a reliable way.

  1. Preparation:
echo "dwc2" >> /etc/modules
echo "libcomposite" >> /etc/modules
echo "dtoverlay=dwc2" >> /boot/config.txt
  1. Copy HID file:
cp usb-hid /usr/bin/
  1. Add /usr/bin/usb-hid to rc.local
  2. Reboot
  3. Clone https://github.com/aagallag/hid_gadget_test
  4. make
  5. chmod +x hid-gadget-test
  6. Use hid-gadget-test to use the mouse:
# move mouse (100,100)
echo ' 100 100' | ./hid-gadget-test/dev/hidg0 mouse > /dev/null
# move mouse (100,100) and hold button b1
echo '--hold --b1 100 100' | ./hid-gadget-test /dev/hidg0 mouse > /dev/null

If you get something error like Cannot send after transport endpoint shutdown, the Raspberry Pi is not properly connected to your device or was not recognized. Reconnect your cables!