This repository hosts Raspi code for turning an Pi Pico into a mouse jiggler.
A mouse jiggler is a either a hardware appliance of a software program for mouse cursor movement automation for the purpose of preventing a computer from going to sleep. Sometimes software-based solutions are locked down by IT departments at which point hardware-based solutions save the day.
While researching how to implement this, I've found that someone has already done exactly what I intended: Raspberry Pi Pico - DIY USB Mouse Jiggler.
The person also made his code available on GitHub: novaspirit/PicoMouseJiggler
import time
import usb_hid
from adafruit_hid.mouse import Mouse
mouse = Mouse(usb_hid.devices)
shift = 2
wait = 0.25
while True:
mouse.move(x=shift, y=shift)
time.sleep(wait)
mouse.move(x=shift, y=-shift)
time.sleep(wait)
mouse.move(x=-shift, y=-shift)
time.sleep(wait)
mouse.move(x=-shift, y=shift)
time.sleep(wait)
This code will move the mouse in a diagonal shape, staying around the origin and not sliding off.
To make the on-board LED light up when active, see #1.
I'm using a Raspberry Pi Pico:
- Press and hold the BOOTSEL button on the Pi Pico
- Connect the Pico to the computer using a data+power USB cable
- Find the RPI-RP2 mass storage device that should mount and release the button
- Download CircuitPython UF2 https://circuitpython.org/board/raspberry_pi_pico
- Wait for the RPI-RP2 drive to unmount itself and reconnect it to the computer
- Wait for a new device to mount called CIRCUITPY
- Go to https://github.com/adafruit/Adafruit_CircuitPython_HID and download it
- Move
adafruit_hid
from the downloaded repository over toCIRCUITPY/lib
- Open
CIRCUITPY/code.py
and edit it to have the above content
There seems to be an issue with macOS currently:
https://github.com/adafruit/Adafruit_CircuitPython_HID/issues/59
Everything works as expected on Windows.
I've implemented a Raspberry Pi based mouse jiggler in a complementary repo: https://github.com/TomasHubelbauer/arduino-mouse-jiggler
Buy these connectors and find somewhere to buy a USB C one, solder the adapters together and use the mouse jiggler by directly connecting it to the computer using the adapter instead of using a short cable which makes it flail around and be overall ugly.