Now with added rickrolling. A program to mess with people. Intended for small boards with built in USB sockets that connect direct to the CPU and can easily be hidden behind a computer (e.g. the mBuino).

Dependencies:   USBDevice mbed

Pretends to be a USB mouse and keyboard and has some predefined functions for various things (do a google image search on a set keyword every 5 minutes, move the mouse in a circle, keep turning the capslock key on etc...)

The default is to rickroll the user. It turns caps lock on, when the user turns it off again the program will turns the volume up to max and load a youtube video of Rick Astley. For the next 45 seconds the mouse will do some circles to make it harder to stop the video. It will then wait 10 minutes and loop back to the start.

As google used to say: Don't be evil. But there is nothing wrong with being a little bit naughty.

Committer:
AndyA
Date:
Thu Dec 17 21:21:06 2015 +0000
Revision:
1:f2747e954f10
Parent:
0:499d030c3e22
Child:
2:15eab46e805b
Added mouse stuff and caps lock fun

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AndyA 0:499d030c3e22 1 #include "mbed.h"
AndyA 0:499d030c3e22 2 #include "USBMouseKeyboard.h"
AndyA 1:f2747e954f10 3 #include "searchText.h"
AndyA 0:499d030c3e22 4
AndyA 1:f2747e954f10 5
AndyA 1:f2747e954f10 6 /*
AndyA 1:f2747e954f10 7 Magic key combos
AndyA 0:499d030c3e22 8
AndyA 1:f2747e954f10 9 r + logo - open run box
AndyA 1:f2747e954f10 10 m + logo - minimise all
AndyA 1:f2747e954f10 11 m + logo + shift - maximise all
AndyA 1:f2747e954f10 12 right arrow + logo + shift - move current window right one monitor
AndyA 1:f2747e954f10 13 l + logo - lock screen
AndyA 1:f2747e954f10 14 */
AndyA 0:499d030c3e22 15
AndyA 1:f2747e954f10 16 #define KEY_ENTER 0x0a
AndyA 0:499d030c3e22 17
AndyA 0:499d030c3e22 18 // turn off all LEDs (some boards they glow a bit if you don't).
AndyA 0:499d030c3e22 19 // you may need to remove some depending on the board.
AndyA 1:f2747e954f10 20 //BusOut LEDs(LED1, LED2, LED3, LED4, LED5, LED6, LED7);
AndyA 1:f2747e954f10 21 int LEDs;
AndyA 1:f2747e954f10 22 USBMouseKeyboard keyboard;
AndyA 1:f2747e954f10 23
AndyA 1:f2747e954f10 24
AndyA 1:f2747e954f10 25 /// Run image searches at interval seconds for given number of repeats or -1 to run forever
AndyA 1:f2747e954f10 26 void startSearches(float interval, int number);
AndyA 1:f2747e954f10 27
AndyA 1:f2747e954f10 28 // enter a keyboard string
AndyA 1:f2747e954f10 29 void sendString(const char *str);
AndyA 1:f2747e954f10 30
AndyA 1:f2747e954f10 31 // draw a mouse circle
AndyA 1:f2747e954f10 32 void drawCircle(float radius, float time, bool dir=true);
AndyA 1:f2747e954f10 33
AndyA 1:f2747e954f10 34 // draw a mouse line
AndyA 1:f2747e954f10 35 void drawLine(float length, float time, bool horizontal=true, bool direction=true);
AndyA 1:f2747e954f10 36
AndyA 1:f2747e954f10 37 // Turn caps lock on n seconds after they turn it off.
AndyA 1:f2747e954f10 38 void forceCaps(float delay, float checkPeriod=0.5);
AndyA 1:f2747e954f10 39
AndyA 1:f2747e954f10 40
AndyA 1:f2747e954f10 41 main()
AndyA 1:f2747e954f10 42 {
AndyA 1:f2747e954f10 43 LEDs = 0;
AndyA 1:f2747e954f10 44 wait(10);
AndyA 1:f2747e954f10 45 forceCaps(5);
AndyA 1:f2747e954f10 46 while (true) {
AndyA 0:499d030c3e22 47
AndyA 1:f2747e954f10 48 }
AndyA 1:f2747e954f10 49 }
AndyA 1:f2747e954f10 50
AndyA 1:f2747e954f10 51 int searchCount;
AndyA 1:f2747e954f10 52 int searchStop;
AndyA 1:f2747e954f10 53 Ticker searchTicker;
AndyA 1:f2747e954f10 54
AndyA 1:f2747e954f10 55 void doNextSearch()
AndyA 1:f2747e954f10 56 {
AndyA 1:f2747e954f10 57 static int searchIndex = 0;
AndyA 1:f2747e954f10 58 keyboard.keyCode('r',KEY_LOGO); // windows key an R
AndyA 1:f2747e954f10 59 wait(0.1); // delay to give the run box a chance to come up.
AndyA 1:f2747e954f10 60 sendString(searchPrefix);
AndyA 1:f2747e954f10 61 sendString( searches[searchIndex++] );
AndyA 1:f2747e954f10 62 sendString(searchSuffix);
AndyA 1:f2747e954f10 63 wait(0.05); // delay to give the run box a chance to come up.
AndyA 1:f2747e954f10 64 keyboard.putc(0x0a); // hit enter
AndyA 1:f2747e954f10 65 if (searchIndex == searchStringCount)
AndyA 1:f2747e954f10 66 searchIndex = 0;
AndyA 1:f2747e954f10 67
AndyA 1:f2747e954f10 68 searchCount++;
AndyA 1:f2747e954f10 69 if (searchCount == searchStop)
AndyA 1:f2747e954f10 70 searchTicker.attach(NULL,0);
AndyA 1:f2747e954f10 71 }
AndyA 1:f2747e954f10 72
AndyA 1:f2747e954f10 73 void startSearches(float interval, int number)
AndyA 1:f2747e954f10 74 {
AndyA 1:f2747e954f10 75 searchCount = 0;
AndyA 1:f2747e954f10 76 searchStop = number;
AndyA 1:f2747e954f10 77 searchTicker.attach(doNextSearch,interval);
AndyA 1:f2747e954f10 78 }
AndyA 0:499d030c3e22 79
AndyA 0:499d030c3e22 80 void sendString(const char *str)
AndyA 0:499d030c3e22 81 {
AndyA 0:499d030c3e22 82 while (*str != 0) {
AndyA 0:499d030c3e22 83 keyboard.putc(*str);
AndyA 0:499d030c3e22 84 str++;
AndyA 0:499d030c3e22 85 }
AndyA 0:499d030c3e22 86 }
AndyA 0:499d030c3e22 87
AndyA 1:f2747e954f10 88 void drawCircle(float radius, float time, bool dir)
AndyA 0:499d030c3e22 89 {
AndyA 0:499d030c3e22 90
AndyA 0:499d030c3e22 91 const float timeStep = 0.05;
AndyA 0:499d030c3e22 92 float currentx = 0;
AndyA 0:499d030c3e22 93 float currenty = radius;
AndyA 0:499d030c3e22 94 int steps = time/timeStep;
AndyA 0:499d030c3e22 95 float angleDelta = 2*3.14159265359 / steps;
AndyA 0:499d030c3e22 96 float xPos,yPos;
AndyA 0:499d030c3e22 97
AndyA 0:499d030c3e22 98 if (!dir)
AndyA 0:499d030c3e22 99 angleDelta = -angleDelta;
AndyA 0:499d030c3e22 100
AndyA 0:499d030c3e22 101
AndyA 0:499d030c3e22 102 for (int i = 0; i<steps; i++) {
AndyA 0:499d030c3e22 103 xPos = radius*sin(angleDelta*i);
AndyA 0:499d030c3e22 104 yPos = radius*cos(angleDelta*i);
AndyA 0:499d030c3e22 105 int xDelta = ((xPos - currentx) > 0)?(xPos - currentx) + 0.5 : (xPos - currentx) - 0.5 ;
AndyA 0:499d030c3e22 106 int yDelta = ((yPos - currenty) > 0)?(yPos - currenty) + 0.5 : (yPos - currenty) - 0.5 ;
AndyA 0:499d030c3e22 107 keyboard.move(xDelta,yDelta);
AndyA 0:499d030c3e22 108 currentx += xDelta;
AndyA 0:499d030c3e22 109 currenty += yDelta;
AndyA 0:499d030c3e22 110 wait(timeStep);
AndyA 0:499d030c3e22 111 }
AndyA 0:499d030c3e22 112 }
AndyA 0:499d030c3e22 113
AndyA 1:f2747e954f10 114 void drawLine(float length, float time, bool horizontal, bool direction)
AndyA 0:499d030c3e22 115 {
AndyA 0:499d030c3e22 116
AndyA 0:499d030c3e22 117 const float timeStep = 0.05;
AndyA 0:499d030c3e22 118 float currentPos = 0;
AndyA 0:499d030c3e22 119 int steps = time/timeStep;
AndyA 0:499d030c3e22 120 float stepSize = length / steps;
AndyA 0:499d030c3e22 121 float movement;
AndyA 0:499d030c3e22 122
AndyA 0:499d030c3e22 123 if (!direction)
AndyA 0:499d030c3e22 124 stepSize = -stepSize;
AndyA 0:499d030c3e22 125
AndyA 0:499d030c3e22 126 for (int i = 0; i<steps; i++) {
AndyA 0:499d030c3e22 127
AndyA 0:499d030c3e22 128 movement = stepSize*i - currentPos;
AndyA 0:499d030c3e22 129 int moveDelta;
AndyA 0:499d030c3e22 130 if (movement>0)
AndyA 0:499d030c3e22 131 moveDelta = movement+0.5;
AndyA 0:499d030c3e22 132 else
AndyA 0:499d030c3e22 133 moveDelta = movement-0.5;
AndyA 0:499d030c3e22 134
AndyA 0:499d030c3e22 135 if (horizontal)
AndyA 0:499d030c3e22 136 keyboard.move(moveDelta,0);
AndyA 0:499d030c3e22 137 else
AndyA 0:499d030c3e22 138 keyboard.move(0,moveDelta);
AndyA 0:499d030c3e22 139
AndyA 0:499d030c3e22 140 currentPos += moveDelta;
AndyA 0:499d030c3e22 141 wait(timeStep);
AndyA 0:499d030c3e22 142 }
AndyA 0:499d030c3e22 143 }
AndyA 0:499d030c3e22 144
AndyA 1:f2747e954f10 145 Ticker capLockTick;
AndyA 1:f2747e954f10 146 Timeout capLockTimer;
AndyA 1:f2747e954f10 147 bool capsTimerActive = false;
AndyA 1:f2747e954f10 148 float capsWaitPeriod = 60;
AndyA 1:f2747e954f10 149
AndyA 1:f2747e954f10 150 void capsOn(void)
AndyA 0:499d030c3e22 151 {
AndyA 1:f2747e954f10 152 capsTimerActive = false;
AndyA 1:f2747e954f10 153 if ((keyboard.lockStatus() & 0x02) == 0)
AndyA 1:f2747e954f10 154 keyboard.keyCode(KEY_CAPS_LOCK);
AndyA 0:499d030c3e22 155 }
AndyA 0:499d030c3e22 156
AndyA 1:f2747e954f10 157 void checkCapsLock(void)
AndyA 0:499d030c3e22 158 {
AndyA 1:f2747e954f10 159 LEDs = keyboard.lockStatus();
AndyA 1:f2747e954f10 160 if ((keyboard.lockStatus() & 0x02) == 0) {
AndyA 1:f2747e954f10 161 if (!capsTimerActive) {
AndyA 1:f2747e954f10 162 capLockTimer.attach(capsOn,capsWaitPeriod);
AndyA 1:f2747e954f10 163 capsTimerActive = true;
AndyA 1:f2747e954f10 164 }
AndyA 1:f2747e954f10 165 } else {
AndyA 1:f2747e954f10 166 if (capsTimerActive) {
AndyA 1:f2747e954f10 167 capLockTimer.detach();
AndyA 1:f2747e954f10 168 capsTimerActive = false;
AndyA 1:f2747e954f10 169 }
AndyA 0:499d030c3e22 170 }
AndyA 0:499d030c3e22 171 }
AndyA 1:f2747e954f10 172
AndyA 1:f2747e954f10 173 void forceCaps(float delay, float checkPeriod) {
AndyA 1:f2747e954f10 174 if (checkPeriod == 0)
AndyA 1:f2747e954f10 175 capLockTick.attach(NULL,0);
AndyA 1:f2747e954f10 176 else {
AndyA 1:f2747e954f10 177 capsWaitPeriod = delay;
AndyA 1:f2747e954f10 178 capLockTick.attach(checkCapsLock,checkPeriod);
AndyA 1:f2747e954f10 179 }
AndyA 1:f2747e954f10 180 }