Overview

Ever had your cursor move a little bit while you weren't even touching the mouse? Freaky! This MakeCode program will turn your Gemma M0 into a Phantom Mouse Jiggler. When plugged in to a computer, it will wait patiently, and then occasionally take over the mouse cursor from the user and move it around back and forth. Maddening!

ALERT: do not use this knowledge for evil. Never use such a device on a computer that plays a critical role in safety, health, or security environments. This is best used a prank when you are nearby to prevent the user from smashing their machine to bits in frustration!

One very powerful feature of the Gemma M0 (and other ATSAMD21 ARM Cortex M0-based microcontrollers) is its ability to appear as a keyboard or mouse when plugged into a computer’s USB port.

The Gemma M0 can pretend to be a USB mouse, so we'll take a look at how to program it with MakeCode to wait dormant for long periods of time, and then jiggle the cursor for a few seconds!

You can code this project up using any 'M0 board that MakeCode supports, including the Metro M0, Trinket M0, even the Circuit Playground Express!

Parts

All you'll need is a Gemma M0 and a short USB cable to program and then deploy this prank!

1 x Gemma M0
Powerful yet small microcontroller
1 x USB Cable
A/Micro B - 6"

Code the Phantom Mouse Jiggler

Create a MakeCode Project

First, head to the Maker.MakeCode site in your web browser. This version of MakeCode is in beta as of the writing of this guide, and it expands the available boards beyond the Circuit Playground Express to include the Gemma M0, Trinket M0, Metro M0 Express, and Feather M0 Express. 

If you're building this project with a Circuit Playground Express, go to the 'regular' MakeCode website, and just skip the first step where you pick which board to use.

Click on the Gemma M0 image to select it.

Now, click the New Project button to create a new program using the Gemma M0.

Building Blocks

This is the default MakeCode screen. On the left is the simulator which can be used to test your program before uploading it to the Gemma M0.

In the center is the palate of programing block categories.

On the right is the canvas where you'll drag blocks to create your program.

Extension

While there is plenty you can do with the default blocks in MakeCode, sometimes you need to add an extension for special behavior. Click on the Advanced item in the category palette, then click on Extensions.

Next, click on the mouse extension. As it says, this will add blocks capable of USB mouse emulation over HID.

Mouse Blocks

This will add a mouse category to the palette -- click on it, then drag to the canvas a mouse move x 0 y 0 block.

You can also create blocks that turn the mouse wheel and click the mouse buttons! We won't use them in the project, but think about ways you could add those to your prank arsenal!

Move Forever

Place the mouse move block inside the forever block. Change the values from 0,0 to 7, -3.

Then, from the loop category, add a pause 500 block as shown, and change the value to 5000 milliseconds. This will cause the cursor to move every five seconds.

Testing

This is a good time to test out your code! Give the program a name, such as 'Mouse_Jiggler' and then press the Download button and save the file to a convenient location on disk.

Plug your Gemma M0 into the computer with the USB cable and then press the reset button on the board to enter bootloader mode. The USB disk will show up as GEMMABOOT.

Drag the .uf2 file you saved onto the Gemma M0.

Now, wait five seconds and then watch your cursor move all on it's own!

This is pretty good, but we can increase the fun by making a repeating back-and-forth loop.

Wiggle Wiggle

From the loops category, drag a repeat 4 times block into the forever block.

Duplicate your existing pause and mouse move blocks and arrange them as shown. Adjust the values as follows, from top to bottom:

  • pause 5000
  • repeat 7 times
  • mouse move x 22 y -9
  • pause 100
  • mouse move x -22 y 9
  • pause 100

Download this new version and then upload it to your Gemma M0. Now, every five seconds, the mouse cursor will wiggle back and forth quite a bit seven times and then stop, repeat forever!

Long Delay

Before you deploy this prank on your victim, increase the delay time to ten minutes (600,000 milliseconds). This is just enough time that they'll ignore it when it happens the first couple of times. Evil fun!

This is the final MakeCode:

What other kinds of movements, loops, and patterns can you create in order to increase the jiggly madness?!

If you enjoyed this project, take a look at the Foul Fowl project, a USB HID keystroke injection payload tool you can make with the Gemma M0 and CircuitPython!

This guide was first published on Mar 12, 2018. It was last updated on Mar 12, 2018.