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).
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.
Diff: main.cpp
- Revision:
- 1:f2747e954f10
- Parent:
- 0:499d030c3e22
- Child:
- 2:15eab46e805b
--- a/main.cpp Thu Dec 10 15:05:58 2015 +0000 +++ b/main.cpp Thu Dec 17 21:21:06 2015 +0000 @@ -1,31 +1,81 @@ #include "mbed.h" #include "USBMouseKeyboard.h" +#include "searchText.h" -// number of search terms -const int searchCount = 6; -// search terms. Should be url encoded (e.g. space becomes %20) -const char *searches[] = {"hot%20cheese", - "big%20show", - "hot%20cheese", - "magic%20mike%20xxl", - "hot%20wet%20cheese", - "hot%20wet%20-cheese" - }; -// pause between searches in seconds -const float delayBetweenSearches = 120; + +/* +Magic key combos -// start of the search string -const char searchPrefix[] = "https://www.google.co.uk/search?q="; +r + logo - open run box +m + logo - minimise all +m + logo + shift - maximise all +right arrow + logo + shift - move current window right one monitor +l + logo - lock screen +*/ -// end of the seach string (an image search with safe search switched off) -const char searchSuffix[] = "&safe=off&tbm=isch"; - +#define KEY_ENTER 0x0a // turn off all LEDs (some boards they glow a bit if you don't). // you may need to remove some depending on the board. -BusOut LEDs(LED1, LED2, LED3, LED4, LED5, LED6, LED7); +//BusOut LEDs(LED1, LED2, LED3, LED4, LED5, LED6, LED7); +int LEDs; +USBMouseKeyboard keyboard; + + +/// Run image searches at interval seconds for given number of repeats or -1 to run forever +void startSearches(float interval, int number); + +// enter a keyboard string +void sendString(const char *str); + +// draw a mouse circle +void drawCircle(float radius, float time, bool dir=true); + +// draw a mouse line +void drawLine(float length, float time, bool horizontal=true, bool direction=true); + +// Turn caps lock on n seconds after they turn it off. +void forceCaps(float delay, float checkPeriod=0.5); + + +main() +{ + LEDs = 0; + wait(10); + forceCaps(5); + while (true) { -USBMouseKeyboard keyboard; + } +} + +int searchCount; +int searchStop; +Ticker searchTicker; + +void doNextSearch() +{ + static int searchIndex = 0; + keyboard.keyCode('r',KEY_LOGO); // windows key an R + wait(0.1); // delay to give the run box a chance to come up. + sendString(searchPrefix); + sendString( searches[searchIndex++] ); + sendString(searchSuffix); + wait(0.05); // delay to give the run box a chance to come up. + keyboard.putc(0x0a); // hit enter + if (searchIndex == searchStringCount) + searchIndex = 0; + + searchCount++; + if (searchCount == searchStop) + searchTicker.attach(NULL,0); +} + +void startSearches(float interval, int number) +{ + searchCount = 0; + searchStop = number; + searchTicker.attach(doNextSearch,interval); +} void sendString(const char *str) { @@ -35,7 +85,7 @@ } } -void drawCircle(float radius, float time, bool dir=true) +void drawCircle(float radius, float time, bool dir) { const float timeStep = 0.05; @@ -61,8 +111,7 @@ } } - -void drawLine(float length, float time, bool horizontal=true, bool direction=true) +void drawLine(float length, float time, bool horizontal, bool direction) { const float timeStep = 0.05; @@ -93,33 +142,39 @@ } } -void doNextSearch() +Ticker capLockTick; +Timeout capLockTimer; +bool capsTimerActive = false; +float capsWaitPeriod = 60; + +void capsOn(void) { - static int searchIndex = 0; - keyboard.keyCode('r',KEY_LOGO); // windows key an R - wait(0.1); // delay to give the run box a chance to come up. - sendString(searchPrefix); - sendString( searches[searchIndex++] ); - sendString(searchSuffix); - wait(0.05); // delay to give the run box a chance to come up. - keyboard.putc(0x0a); // hit enter - if (searchIndex == searchCount) - searchIndex = 0; + capsTimerActive = false; + if ((keyboard.lockStatus() & 0x02) == 0) + keyboard.keyCode(KEY_CAPS_LOCK); } - -main() +void checkCapsLock(void) { - LEDs = 0; - wait(10); - while (true) { - doNextSearch(); - - drawCircle(45,delayBetweenSearches/12); - drawCircle(45,delayBetweenSearches/12,false); - wait(delayBetweenSearches/4); - drawCircle(60,delayBetweenSearches/6,false); - drawCircle(80,delayBetweenSearches/6); - wait(delayBetweenSearches/4); + LEDs = keyboard.lockStatus(); + if ((keyboard.lockStatus() & 0x02) == 0) { + if (!capsTimerActive) { + capLockTimer.attach(capsOn,capsWaitPeriod); + capsTimerActive = true; + } + } else { + if (capsTimerActive) { + capLockTimer.detach(); + capsTimerActive = false; + } } } + +void forceCaps(float delay, float checkPeriod) { + if (checkPeriod == 0) + capLockTick.attach(NULL,0); + else { + capsWaitPeriod = delay; + capLockTick.attach(checkCapsLock,checkPeriod); + } + }