Sider

fredag 6. juli 2012

Arduino key board Prank


I work at an office and there is always some pranks going around. One of them was plugging a second keyboard in to the computer and typing away while the other guy was trying to write emails.
So I thought way not make it a little more advanced, and make a device to do it all for me. I had an old teensy 1.0++ laying around. So the prank is as easy as setting it up to emulate a usb keyboard. Then have it press keys and write messages with a set interval. The way I programmed it in the code under is:

First hours: toggle caps lock every 2.5 min
Second hours: Press alt-tab (change window) every 2.5 min
Rest of the day: Type random messages on the screen

The teensy board
As you can see this quickly gets pretty irritating. But when you start looking for who’s pranking you the regular guy is sitting quietly typing on his key board. And it’s easy to change for your own messages and keys.
To make it less detectable you can use a USB-hub, so that there is no more cables then usual going in to the computer.


/*
Arduino USB key borad prank
*/

int count = 0;
bool caps;

void setup() {
delay(1000);
}

// toggle caps-lock
void toggle_caps_lock() {
if (!caps) {
Keyboard.set_key1(KEY_CAPS_LOCK);
caps = true;
} else
{
Keyboard.set_key1(0);
caps = false;
}

Keyboard.send_now();
}

// ALT-TAB
void chage_app() {
Keyboard.set_modifier(MODIFIERKEY_ALT); // Press alt
Keyboard.send_now();
Keyboard.set_key1(KEY_TAB); // Press tab
Keyboard.send_now();

Keyboard.set_key1(0); // Release keys
Keyboard.set_modifier(0);
Keyboard.send_now();
}


void write_rnd_msg() {
char* msg[15];

msg[0] = "I am a sucker ";
msg[1] = "Hugs and kisses ";
msg[2] = "stupid ";
msg[3] = "Whats going on with my computer ";
msg[4] = "Im messing with you ";
msg[5] = "What??? ";

int rand = random(0, 5);

Keyboard.print(msg[rand]);
}

void loop() {
count = count + 1;

if (count < 120) { // first hour
if ((count%5) == 0) {
toggle_caps_lock();
}
}

if ((count < 240)&&(count > 120)) { // second hour
if ((count%5) == 0) {
chage_app();
}
}


if (count > 240) { // the rest of the day
if ((count%10) == 0) {
write_rnd_msg();
}
}
delay(30000);
}