Skip to content

Instantly share code, notes, and snippets.

@mtlynch
Last active February 24, 2023 22:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mtlynch/906534da530482e9afcf1e1309b3dbbe to your computer and use it in GitHub Desktop.
Save mtlynch/906534da530482e9afcf1e1309b3dbbe to your computer and use it in GitHub Desktop.
#!/bin/bash
# Set TinyPilot to jiggle the mouse every 3 seconds.
# Author: Michael Lynch
# https://tinypilotkvm.com
# License: MIT License
set -e
set -u
# Change the value below to any you want
readonly TIME_BETWEEN_JIGGLES="3s"
i=0
while true
do
echo "$(date --iso-8601=seconds):" "Moving mouse cursor"
if (( $i % 2 )); then
echo -ne "\0\x03\x16\x58\x4c\0\0" > /dev/hidg1
else
echo -ne "\0\xbc\x1b\xdd\x2a\0\0" > /dev/hidg1
fi
i=$((i+1))
sleep "${TIME_BETWEEN_JIGGLES}"
done
@domdorn
Copy link

domdorn commented Apr 29, 2022

is there a documentation somewhere what these hex values mean? I'd like to understand them to make my own scripts for tinypilot mouse movement.

@mtlynch
Copy link
Author

mtlynch commented Apr 29, 2022

@domdorn - Sure, they're USB HID messages. You can see how they're generated here:

https://github.com/tiny-pilot/tinypilot/blob/f89a5ee77d4af763e4b9ad85767e5fb16175ae93/app/hid/mouse.py

They correspond to the USB HID descriptor we use for TinyPilot, which you can see here:

https://github.com/tiny-pilot/ansible-role-tinypilot/blob/94e97fffbda088c03b0ffe0f60e9c12471d4ddc8/files/init-usb-gadget#L103L149

This blog post has a good explanation about USB HID messages. It's about keystrokes, but a lot of the concepts apply to the mouse movement messages as well:

https://www.rmedgar.com/blog/using-rpi-zero-as-keyboard-send-reports/

And if you want to get really down into the technical details, here's the full spec:

https://www.usb.org/document-library/device-class-definition-hid-111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment