USB Shenanigans

Preamble

I was watching youtube tutorials, and saw this video.
Arduino Tutorial #14: Leonardo as Mouse

This immediately appealed to my mischievous side. I thought it would be amusing to load this into a Leonardo, or other 32u2 based Arduino, and then surreptitiously plug it into someone’s computer. However, a Leonardo would be a bit obvious, having it hanging out of the USB port, so a discrete Micro seemed to be the best bet. For dual use, as I was also after a 3.3V Micro for replacing the Pro Mini 3.3V in my Arduino hoody, as I had read somewhere about someone waking up their PC, by simulating a mouse shake from a Pi, via an Arduino, Wake up Windows PC via USB event from a Raspberry Pi.

NOTE: Be aware that it is very easy to brick your Pro Micro during these experiments, as is related in the tale of The case of the broken Pro Micro.

See also the blog, Arduino Joystick shield, Nokia 5110 display and BlueTooth, for other USB mouse related Arduino sketches

The purchase

So, onto eBay, and the cheapest 3.3V Chinese clone of a Pro Micro was the New Pro Micro ATmega32U4 3.3V 8MHz Replace ATmega328 Arduino Pro Mini M94, for £3.20. The purchase was made in a matter of seconds.

The code

While I was waiting for it to arrive, I set about getting the code in order. The code is linked to in the video (above) and can be downloaded from dropbox. The code, complete with my ameliorations for OS X mice, is below:


void setup()
{
pinMode(2,INPUT);
digitalWrite(2,HIGH);

randomSeed(millis());
}

void loop()
{
if(digitalRead(2) == LOW)
{
Mouse.begin();

switch(random(0,3))
{
case 0: //Press the right mouse button
Mouse.press(MOUSE_RIGHT);
delay(100);
Mouse.release(MOUSE_RIGHT);
break;

case 1: //Jiggle the mouse
Mouse.move(random(-128,128),random(-128,128), 0);
break;

case 2: //Double click left mouse button
Mouse.press(MOUSE_LEFT);
delay(100);
Mouse.release(MOUSE_LEFT);
delay(100);
Mouse.press(MOUSE_LEFT);
delay(100);
Mouse.release(MOUSE_LEFT);
break;
}

delay(random(60*1000,5*60*1000));
}
else
{
Mouse.end();
}
}

Also useful?

These links appear to be for using the Pro Micro as a USB input device

blah

Advertisements

One thought on “USB Shenanigans”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s