Command to simulate input over USB


browse  log 



You can also use your local clone with git send-email.


gadget is a Linux command to send input and data over USB, appearing as a composite keyboard, mouse and serial device. The machine running gadget must have USB OTG (On-The-Go), like most smartphones and some Raspberry Pi.

I have tested the Raspberry Pi 4, and the 0, 0W, 02W, A and A+ should also work, but not the B, B+, 2, 3, 3A+ and 3B+.




#Plug In

With a Raspberry Pi, you plug the small end of a micro USB cable into the Pi and the big end into a port on your computer. A blue (USB 3.0) port on the back of your computer is probably the best bet. There's a chance a cable doesn't support USB OTG, but the few I've tried have all worked. The cable both powers the Pi and carries the data.


See gadget --help for everything but you first run:

gadget init

and then you can do stuff:

echo 'key h i shift+1' | gadget

echo 'type Sup, Lads!' | gadget

{ echo keydown A; sleep 3; echo key H shift+1; } | gadget

printf %s\\n 'buttondown left' 'mousemove 0 100' 'buttonup left' | gadget

There's also gadget-relay and gadget-xrelay to pass your input through to the other machine.

#Numen, Chat and Contact

gadget was written for Numen Voice Control and you're very welcome to join the Matrix chat at #numen:matrix.org.

You can also send questions, thoughts or patches by composing an email to ~geb/public-inbox@lists.sr.ht.

#Support Me

Thank you!


GPLv3 only, see LICENSE.

Copyright (c) 2023 John Gebbie