# Why?

Needed to stop my laptop from entering sleep and Skype from setting me as away. So I needed something that appears as a Human Interface Device (HID) and randomly sends a mouse input every three minutes or so.

## Pre-requisites

You’ll need to install CircuitPython version 7.0.0 or higher first, otherwise you won’t be able to make the device identify as USB HID without rebuilding CircuitPython.

I used an Adafruit Neo Trinkey and a Raspberry Pico. Neither are expensive, I paid £6.30 and £3.60 respectively. Trinkey is a bit flashier, doesn’t need a cable, fits on a keyring and has the ability to bypass boot.py by pressing both capacitive keys.

## Code

No point in having a version control system and barking oneself, so the code is on Github. Copy both boot.py and code.py to the device.

I’ll go over the Pico code here but the Neo is similar.

### Make the mouse move

import usb_hid
import board
import digitalio
from time import sleep
from random import randint

HOW_LONG = 180    # Pause between jiggles in seconds

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

mouse = Mouse(usb_hid.devices)

for x in range(times):
led.value = False
sleep(0.5)
led.value = True
print(x)

def jiggle():
for each in range(randint(1, 4)):
x = randint(1, 50)
y = randint(1, 50)
mouse.move(x, y)
mouse.move(-x, -y)
sleep(HOW_LONG)

while True:
led.value = True
jiggle()

Once we know that code is working and more importantly that it works the way you need it to then we can move on to the next step.

### Make the device appear as just HID

The Pico hasn’t got an input so we can’t follow Adafruit’s advice. Once you’ve saved boot.py then you’ll need to use UF2 bootloader erase files for Pico.

I was able to avoid this with the Neo Trinkey by checking at boot time for both capacitive keys being active. Had to put in a delay too, otherwise it is difficult to time. Quite common working with embedded systems that you need to add delays.

import storage
import usb_cdc

storage.disable_usb_drive()    # Disable USB Drive
usb_cdc.disable()              # Disable REP

## If it all goes wrong…

If it all goes wrong and you can’t access either device, then you can reset the flash memory.

### Pico

Disconnect the Pico, hold the BOOTSEL button and keep it depressed while reinserting. When RPI-RP2 drive appears, copy the bootloader file from Adafruit. This will completely reset the Pico.