Skip to content

Instantly share code, notes, and snippets.

@dglaude
Created May 16, 2021 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dglaude/aad3d9e19858b062306b2a514434fd6b to your computer and use it in GitHub Desktop.
Save dglaude/aad3d9e19858b062306b2a514434fd6b to your computer and use it in GitHub Desktop.
Hidden Mouse Jiggler
import time
import board
import digitalio
import storage
import usb_hid
from adafruit_hid.mouse import Mouse
import usb_cdc
#usb_hid.enable(devices=(usb_hid.MOUSE,)) ###AttributeError: 'module' object has no attribute 'MOUSE'
switch = digitalio.DigitalInOut(board.SLIDE_SWITCH)
switch.direction = digitalio.Direction.INPUT
if switch.value:
print("Hiding Drive and Serial")
# storage.disable_usb_drive() ###RuntimeError: Cannot change USB devices now
# usb_cdc.disable() # <= This seems to work
else:
print("Debug mode")
mouse = Mouse(usb_hid.devices)
while True:
print("Looping")
mouse.move(x=20)
time.sleep(5)
mouse.move(x=-20)
time.sleep(5)
@dglaude
Copy link
Author

dglaude commented May 16, 2021

Running this code on a CPB with:

Adafruit CircuitPython 7.0.0-alpha.2-584-g25a44cb77 on 2021-05-15; Adafruit Circuit Playground Bluefruit with nRF52840

The behaviour should be a mouse jiggler with or without visibility of CIRCUITPY drive (and CDC console) depending on the slide switch position.

But:

  1. This code fail on usb_hid.enable(devices=(usb_hid.MOUSE,)):

Press any key to enter the REPL. Use CTRL-D to reload.
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
File "code.py", line 9, in
AttributeError: 'module' object has no attribute 'MOUSE'

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 7.0.0-alpha.2-584-g25a44cb77 on 2021-05-15; Adafruit Circuit Playground Bluefruit with nRF52840

  1. It also fail on storage.disable_usb_drive():

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Hiding Drive and Serial
Traceback (most recent call last):
File "code.py", line 16, in
RuntimeError: Cannot change USB devices now

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 7.0.0-alpha.2-584-g25a44cb77 on 2021-05-15; Adafruit Circuit Playground Bluefruit with nRF52840

@dhalbert
Copy link

dhalbert commented May 16, 2021

As mentioned, you need to put
usb_hid.enable(devices=(usb_hid.Device.MOUSE,)) and storage.disable_usb_drive() in boot.py. By the time you get to code.py, the USB devices are set already.

And it is usb_hid.Device.MOUSE. That should work.

I will be writing a guide soon.

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