Digistump Forums

The Digispark => Digispark Projects => Topic started by: koenig on February 13, 2013, 12:52:02 am

Title: Digispark prank keyboard driver
Post by: koenig on February 13, 2013, 12:52:02 am

I backed the Kickstarter project Digispark a couple of months ago and yesterday I got all the goodies! Yum.

One of my plans, when I saw the Digispark and thought about the potential, was to make a prank keyboard driver - the Digispark is small and innocent and perfect for plugging into colleagues computers without their knowing.

So I wrote a small program that sleeps for six seconds and then picks a random number between 0 and 159. On 0-3 something happens otherwise it goes back to sleep, which means that there is a 1 in 40 chance of a prank.


I picked minimise all windows, minimise one window, turn the screen upside down and lock the computer as rather harmless, still interesting.


Here is the code
Code: [Select]
#include "DigiKeyboard.h"
void setup() {
}


void loop() {
 
 DigiKeyboard.update();
 DigiKeyboard.sendKeyStroke(0); //this is generally not necessary but with some older systems it seems to prevent missing the first character after a delay
 switch (random(160)) {
 case 0: // Minimize all windows
 DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT);
 break;
case 1: // Lock screen
 DigiKeyboard.sendKeyStroke(KEY_L, MOD_GUI_LEFT);
 break;
 
 case 2: // Minimize current window
 DigiKeyboard.sendKeyStroke(KEY_DOWN_ARROW, MOD_GUI_LEFT);
 break;
case 3: // Flip screen
 DigiKeyboard.sendKeyStroke(KEY_DOWN_ARROW, MOD_CONTROL_LEFT + MOD_ALT_LEFT);
 break;
default:
 break;
 }
 
 delay(6000);
}


I also had to make an addition to the DigiKeyboard.h file since it was lacking all but one arrow key:



Code: [Select]

#define KEY_UP_ARROW   0x52
#define KEY_DOWN_ARROW   0x51
#define KEY_LEFT_ARROW   0x50
#define KEY_RIGHT_ARROW   0x4F
Title: Re: Digispark prank keyboard driver
Post by: forsakenrider on March 24, 2013, 08:22:10 pm
I wonder if we can port some of irongeeks phukd libraries to digispark. would make for a nice minimalist pentesting tool!
Title: Re: Digispark prank keyboard driver
Post by: forsakenrider on March 26, 2013, 08:01:11 pm
Heres a fun one, try it on a windows computer!

Code: [Select]
//Wallpaper Prank, modified by DW for use on the digispark

#include "DigiKeyboard.h"



void setup() {
  pinMode(1, OUTPUT); //LED on Model A
 
 
}


void loop() {
 
 
  DigiKeyboard.update();
  DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.delay(3000);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT); //minimize all windows
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_PrintScreen); //prntscr
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_F10, MOD_SHIFT_LEFT); //Open Menu
  DigiKeyboard.delay(200);
  DigiKeyboard.sendKeyStroke(KEY_V);
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_D);
  DigiKeyboard.delay(500); 
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(100);
  DigiKeyboard.println("mspaint");
  DigiKeyboard.delay(1200);
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_CONTROL_LEFT); //paste
  DigiKeyboard.delay(500); 
  DigiKeyboard.sendKeyStroke(KEY_S, MOD_CONTROL_LEFT); //save
  DigiKeyboard.delay(500); 
  DigiKeyboard.println("%userprofile%\\a.bmp"); //save in users folder
  DigiKeyboard.delay(500);
  DigiKeyboard.sendKeyStroke(KEY_F, MOD_ALT_LEFT); //file
  DigiKeyboard.delay(500);
  DigiKeyboard.sendKeyStroke(KEY_K); //set as desktop
  DigiKeyboard.delay(100); 
  DigiKeyboard.sendKeyStroke(KEY_T); //tile
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_F4, MOD_ALT_LEFT); //close paint
  DigiKeyboard.delay(300);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT | MOD_SHIFT_LEFT); //back to desktop as it was
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
 
}
Title: Re: Digispark prank keyboard driver
Post by: forsakenrider on March 26, 2013, 09:39:16 pm
Heres one to update facebook status. you need to add to DigiKeyboard.h:
Code: [Select]
#define KEY_Tab     43
then the code:

Code: [Select]
//  This will only work if the person is generally logged into facebook

#include "DigiKeyboard.h"

void setup() {
  // don't need to set anything up to use DigiKeyboard
}


void loop() {
 
  DigiKeyboard.sendKeyStroke(0);
 
  DigiKeyboard.delay(2000);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT); //minimize all windows
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(100);
  DigiKeyboard.println("https://m.facebook.com/");
  DigiKeyboard.delay(3000);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.println("hello world from the DigiSpark!");
  DigiKeyboard.sendKeyStroke(KEY_Tab);
  DigiKeyboard.sendKeyStroke(KEY_ENTER);
  DigiKeyboard.delay(50000);
}

PS- is there an easier way for the tabs?


Title: Re: Digispark prank keyboard driver
Post by: Bluebie on March 26, 2013, 11:55:13 pm
Sure is! DigiKeyboard.print("\t\t\t\t\t") types in six tabs!
Title: Re: Digispark prank keyboard driver
Post by: forsakenrider on March 27, 2013, 04:45:28 am
Oh, whats easier!

Another question. For my first prank, can I make it save the file as a random number? I tried all sorts of things but I couldn't figure it out. The program doesn't work if there is already an "a.bmp" in the user's folder.


Title: Re: Digispark prank keyboard driver
Post by: Bluebie on March 28, 2013, 12:40:38 am

You could use psuedorandom numbers, but maybe it'd be better to just use an incrementing integer?


You can use the EEPROM library built in to arduino to store bytes in the internal memory, and could have some code in your setup which gets the number, increments it by one, saves it back, and later in your code you can use the incremented number.
Title: Re: Digispark prank keyboard driver
Post by: forsakenrider on March 28, 2013, 05:34:02 am
Thanks for that info! there are so many different ways to go about this, wow.

I'm so glad I bought some digispark boards! I tried getting into arduino but found myself just copy and pasting everything. Now with the limited IO and memory its a lot easier to actually start understanding whats going on. What a great learning platform! I am having so much fun with these!
Title: Re: Digispark prank keyboard driver
Post by: forsakenrider on March 28, 2013, 08:13:31 pm
Heres the final version of the desktop prank.

Now to write one that works on MAC...

Code: [Select]
//Wallpaper Prank, modified by DW for use on the digispark

#include "DigiKeyboard.h"
#include <EEPROM.h>

int a = 0;
int value;


void setup() {
  pinMode(1, OUTPUT); //LED on Model A
  value = EEPROM.read(a);
 
 
  value = value + 1;
  if (value > 100)
    value = 0;
 
 
  EEPROM.write(a, value);
 
 
 
}


void loop() {
 
 
 
  DigiKeyboard.update();
  DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.delay(2000);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT); //minimize all windows
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_PrintScreen); //printscreen
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_F10, MOD_SHIFT_LEFT); //Open Menu
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_V);
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_D);
  DigiKeyboard.delay(50); 
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(50);
  DigiKeyboard.println("mspaint");
  DigiKeyboard.delay(1200);
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_CONTROL_LEFT); //paste
  DigiKeyboard.delay(50); 
  DigiKeyboard.sendKeyStroke(KEY_S, MOD_CONTROL_LEFT); //save
  DigiKeyboard.delay(500);
 
 
  DigiKeyboard.print("%userprofile%\\"); //save in users folder
  DigiKeyboard.print(value); //number saved in eeprom + 1
  DigiKeyboard.println(".bmp");
 
 
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_F, MOD_ALT_LEFT); //file
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_K); //set as desktop
  DigiKeyboard.delay(100); 
  DigiKeyboard.sendKeyStroke(KEY_T); //tile
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_F4, MOD_ALT_LEFT); //close paint
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT | MOD_SHIFT_LEFT); //back to desktop as it was
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(100);
  DigiKeyboard.println("www.digistump.com"); //buy a digispark to get me back
 
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
 
}

Title: Re: Digispark prank keyboard driver
Post by: Bluebie on March 28, 2013, 08:40:46 pm
Here's a version for Mac:


Code: [Select]

//Wallpaper Prank, modified by DW for use on the digispark
#include "DigiKeyboard.h"

void setup() {
  pinMode(1, OUTPUT); //LED on Model A
}




void loop() {
  DigiKeyboard.update();
 
  // take screenshot in to clipboard
  DigiKeyboard.sendKeyStroke(KEY_3, MOD_GUI_LEFT | MOD_CONTROL_LEFT | MOD_SHIFT_LEFT);
  DigiKeyboard.delay(100); // 0.1s delay
  DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT);
  DigiKeyboard.delay(250);
  DigiKeyboard.println("Desktop & Screen Saver");
  DigiKeyboard.delay(2000);
  DigiKeyboard.print("\t"); // tab in to picture hole
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_GUI_LEFT);
  DigiKeyboard.delay(1000);
 
 
  DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT);
  DigiKeyboard.delay(1000);
  DigiKeyboard.println("Safari");
  DigiKeyboard.delay(4000);
  DigiKeyboard.sendKeyStroke(KEY_N, MOD_GUI_LEFT); // new window
  DigiKeyboard.sendKeyStroke(KEY_L, MOD_GUI_LEFT); // set focus to address bar
  DigiKeyboard.println("http://www.digistump.com/"); //buy a digispark to get me back
 
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
  while(true) { DigiKeyboard.update(); }
}


It doesn't need to mess around with files - it just copies in the wallpaper via the clipboard.
Title: Re: Digispark prank keyboard driver
Post by: forsakenrider on March 28, 2013, 09:04:30 pm
Not bad, but that doesnt remove the icons after taking the printscreen.

Can we get to the command line from the spotlight? cuz if so I've found the command for hiding the icons. then after that set the desktop and voila!
Code: [Select]
defaults write com.apple.finder CreateDesktop -bool false

Code: [Select]
killall Finder

then just need to add a simple If statement, a switch or jumper and add the two codes and we have a windows and mac party pooper!
Title: Re: Digispark prank keyboard driver
Post by: Bluebie on March 28, 2013, 09:46:51 pm
Installing system hacks in to the OS that don't have any GUI for reversing the mod steps beyond the realm of prank, in my view.


But if you want a command line, all you need to do is println "Terminal" in to spotlight and wait one second for it to open, then you can enter your commands
Title: Re: Digispark prank keyboard driver
Post by: forsakenrider on March 28, 2013, 09:58:30 pm
very valid point. Heres your version plus my version and a jumper across pins 1 and 3 decides the OS:

Code: [Select]
//Wallpaper Prank, modified by DW for use on the digispark

#include "DigiKeyboard.h"
#include <EEPROM.h>

int a = 0;
int value;
int mac = 0;

void setup() {
  pinMode(0, OUTPUT);
  pinMode(2, INPUT);
  digitalWrite(0,HIGH);
 
  value = EEPROM.read(a);
 
 
  value = value + 1;
  if (value > 100)
    value = 0;
 
 
  EEPROM.write(a, value);
 
 
 
}


void loop() {
 
  mac = digitalRead(2);
 
  if (mac == HIGH) {
 
    DigiKeyboard.update();
 
  // take screenshot in to clipboard
  DigiKeyboard.sendKeyStroke(KEY_3, MOD_GUI_LEFT | MOD_CONTROL_LEFT | MOD_SHIFT_LEFT);
  DigiKeyboard.delay(100); // 0.1s delay
  DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT);
  DigiKeyboard.delay(250);
  DigiKeyboard.println("Desktop & Screen Saver");
  DigiKeyboard.delay(2000);
  DigiKeyboard.print("\t"); // tab in to picture hole
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_GUI_LEFT);
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_SPACE, MOD_GUI_LEFT);
  DigiKeyboard.delay(1000);
  DigiKeyboard.println("Safari");
  DigiKeyboard.delay(4000);
  DigiKeyboard.sendKeyStroke(KEY_N, MOD_GUI_LEFT); // new window
  DigiKeyboard.sendKeyStroke(KEY_L, MOD_GUI_LEFT); // set focus to address bar
  DigiKeyboard.println("http://www.digistump.com/"); //buy a digispark to get me back
 
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
  while(true) { DigiKeyboard.update(); }
}


else{
 
   
  DigiKeyboard.update();
  DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.delay(2000);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT); //minimize all windows
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_PrintScreen); //printscreen
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_F10, MOD_SHIFT_LEFT); //Open Menu
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_V);
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_D);
  DigiKeyboard.delay(50); 
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(50);
  DigiKeyboard.println("mspaint");
  DigiKeyboard.delay(1200);
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_CONTROL_LEFT); //paste
  DigiKeyboard.delay(50); 
  DigiKeyboard.sendKeyStroke(KEY_S, MOD_CONTROL_LEFT); //save
  DigiKeyboard.delay(500);
 
 
  DigiKeyboard.print("%userprofile%\\"); //save in users folder
  DigiKeyboard.print(value); //number saved in eeprom + 1
  DigiKeyboard.println(".bmp");
 
 
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_F, MOD_ALT_LEFT); //file
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_K); //set as desktop
  DigiKeyboard.delay(100); 
  DigiKeyboard.sendKeyStroke(KEY_T); //tile
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_F4, MOD_ALT_LEFT); //close paint
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT | MOD_SHIFT_LEFT); //back to desktop as it was
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(100);
  DigiKeyboard.println("www.digistump.com"); //buy a digispark to get me back
 
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
}
}

I think it should work.
Title: Re: Digispark prank keyboard driver
Post by: willgonz on October 01, 2013, 06:44:00 pm
How can you send a Ctrl-Alt-Del?

Title: Re: Digispark prank keyboard driver
Post by: technodoug on October 17, 2013, 09:13:05 pm
#define KEY_DELETE 76

DigiKeyboard.sendKeyStroke(KEY_DELETE, MOD_ALT_RIGHT | MOD_CONTROL_LEFT);
Title: Re: Digispark prank keyboard driver
Post by: handsomejackuk on January 05, 2016, 05:42:18 pm
bump this for reference
Title: Re: Digispark prank keyboard driver
Post by: gabe on March 29, 2016, 03:15:41 am
Heres a fun one, try it on a windows computer!

Code: [Select]
//Wallpaper Prank, modified by DW for use on the digispark

#include "DigiKeyboard.h"



void setup() {
  pinMode(1, OUTPUT); //LED on Model A
 
 
}


void loop() {
 
 
  DigiKeyboard.update();
  DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.delay(3000);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT); //minimize all windows
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_PrintScreen); //prntscr
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_F10, MOD_SHIFT_LEFT); //Open Menu
  DigiKeyboard.delay(200);
  DigiKeyboard.sendKeyStroke(KEY_V);
  DigiKeyboard.delay(50);
  DigiKeyboard.sendKeyStroke(KEY_D);
  DigiKeyboard.delay(500); 
  DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT); //run
  DigiKeyboard.delay(100);
  DigiKeyboard.println("mspaint");
  DigiKeyboard.delay(1200);
  DigiKeyboard.sendKeyStroke(KEY_V, MOD_CONTROL_LEFT); //paste
  DigiKeyboard.delay(500); 
  DigiKeyboard.sendKeyStroke(KEY_S, MOD_CONTROL_LEFT); //save
  DigiKeyboard.delay(500); 
  DigiKeyboard.println("%userprofile%\\a.bmp"); //save in users folder
  DigiKeyboard.delay(500);
  DigiKeyboard.sendKeyStroke(KEY_F, MOD_ALT_LEFT); //file
  DigiKeyboard.delay(500);
  DigiKeyboard.sendKeyStroke(KEY_K); //set as desktop
  DigiKeyboard.delay(100); 
  DigiKeyboard.sendKeyStroke(KEY_T); //tile
  DigiKeyboard.delay(1000);
  DigiKeyboard.sendKeyStroke(KEY_F4, MOD_ALT_LEFT); //close paint
  DigiKeyboard.delay(300);
  DigiKeyboard.sendKeyStroke(KEY_M, MOD_GUI_LEFT | MOD_SHIFT_LEFT); //back to desktop as it was
 
  digitalWrite(1, HIGH); //turn on led when program finishes
  DigiKeyboard.delay(90000);
  digitalWrite(1, LOW);
  DigiKeyboard.delay(5000);
 
}

I have to add a define for "KEY_PrintScreen". What is the code for it and how can I get it?
Title: Re: Digispark prank keyboard driver
Post by: Leprechaun on April 28, 2016, 03:12:19 am
Hello. Please tell me, how do I pass codes Androyd buttons? Examples: KEYCODE_HOME, KEYCODE_MEDIA_PLAY, KEYCODE_MEDIA_STOP, KEYCODE_NAVIGATE_IN? What should I add to DigiKeyboard.h? How to bring in DigiKeyboard.sendKeyStroke (); ? Please forgive me if you misspelled. My English is bad. Translated using translate.google.
Title: Re: Digispark prank keyboard driver
Post by: Leprechaun on May 02, 2016, 11:39:40 am
Forum dead ? My question too complex? Prefer not to say beginners ?  :(
Title: Re: Digispark prank keyboard driver
Post by: Fardenco on February 18, 2017, 05:58:54 pm
I know it's a quite old thread but hopefully this will help anyone still looking for an answer.

the scan code for printscreen is 70, as you can see in the pictures on this thread
https://digistump.com/board/index.php/topic,2289.0.html (https://digistump.com/board/index.php/topic,2289.0.html)

for media keys, the only solution I've found is to use Adafruit's TrinketHidCombo library
https://github.com/adafruit/Adafruit-Trinket-USB/tree/master/TrinketHidCombo (https://github.com/adafruit/Adafruit-Trinket-USB/tree/master/TrinketHidCombo)

An example here to make a volume knob
https://learn.adafruit.com/trinket-usb-volume-knob/code (https://learn.adafruit.com/trinket-usb-volume-knob/code)
Title: Re: Digispark prank keyboard driver
Post by: Bark3rR on May 31, 2017, 06:58:18 pm
i want to be able to open spotlight search at the beginning of my code, just making sure this is right

DigiKeyboard.sendKeyStroke(0, MOD_GUI_LEFT | KEY_SPACE);

thx.
Title: Re: Digispark prank keyboard driver
Post by: LionRelaxe on March 26, 2018, 12:12:07 pm
Hello,

I needed a variation of the prank, to fool the mouse instead of the keyboard.
Here is a VERY loosely adapted code mashed from two sources:
http://www.instructables.com/id/Mouse-Prank-with-Arduino/ (http://www.instructables.com/id/Mouse-Prank-with-Arduino/)
and from the "DigiMouse" example.

This will move the mouse in a step, each 5 to 60 seconds.
Good luck!

Code: [Select]
// DigiMouse test and usage documentation
// CAUTION!!!! This does click things!!!!!!!!
// Originally created by Sean Murphy (duckythescientist)

#include <DigiMouse.h>


int delayLevel = 5; //set the range of time between action, set to 1-10
int range = 5;              // output range of X or Y movement; affects movement speed
//variables for beep
long freq = 4000; //set beep frequency
long period;
long aSecond = 1000000;
int piezo = 12;

void setup() {
  DigiMouse.delay(2000);
  DigiMouse.begin(); //start or reenumerate USB - BREAKING CHANGE from old versions that didn't require this
  DigiMouse.delay(2000);
}

void loop() {
  // If not using plentiful DigiMouse.delay(), make sure to call
  // DigiMouse.update() at least every 50ms
 
  // move across the screen
  // these are signed chars
/* 
  DigiMouse.moveY(10); //down 10
  DigiMouse.delay(500);
  DigiMouse.moveX(20); //right 20
  DigiMouse.delay(500);
  DigiMouse.scroll(5);
  DigiMouse.delay(500);
 
  // or DigiMouse.move(X, Y, scroll) works
 
  // three buttons are the three LSBs of an unsigned char
  DigiMouse.setButtons(1<<0); //left click
  DigiMouse.delay(500);
  DigiMouse.setButtons(0); //unclick all
  DigiMouse.delay(500);

  //or you can use these functions to click
  DigiMouse.rightClick();
  DigiMouse.delay(500);
  DigiMouse.leftClick();
  DigiMouse.delay(500);
  DigiMouse.middleClick();
  DigiMouse.delay(500);

  //for compatability with other libraries you can also use DigiMouse.move(X, Y, scroll, buttons)
  */
 
  //========================================
  //Jump with variable delay

  unsigned long randomDelay = random(5,60); //generate random number for delay
  //unsigned long thisDelay = randomDelay * long (delayLevel) * 1000;
  //Serial.println (thisDelay);
  //unsigned long next = long (millis()) + thisDelay;
  unsigned long next =  (millis() + randomDelay*1000);
  while ((millis() < next) && (millis() > 200)){
      DigiMouse.delay (100);
  }
  //call Jump
  int distanceX = random(100,500); //set jump distance, direction is set in function
  int distanceY = random(100,500); //set jump distance, direction is set in function
  DigiMouse.moveX (distanceX); // modify with math for different results
  DigiMouse.update();
  DigiMouse.moveY (distanceY); // modify with math for different results
  DigiMouse.update();
  DigiMouse.delay (10);
  //jump (distance);  //uncomment this to use jump without beep
  //jumpBeep (distance);  //uncomment this to use jump with a beep


/*
//===========================
  //Jitter with fixed delay
 
  jitter (12);
  delay (60000);
  */
  //===========================
  //Jitter with variable delay
 /*
  long randomDelay = random(30,60); //generate random number for delay
  long thisDelay = randomDelay * long (delayLevel) * 1000;
  Serial.println (thisDelay);
  long next = long (millis()) + thisDelay;
  while (millis() < next){
    //wait
  }
  //call Jitter
  jitter (12); //call jitter function with number of repeats/duration
 */
 
//============================
 
  //Jump with fixed delay
 
  /*
  jump (-150);
  delay (125000);
  */

}


//===============subs=============

void jump(int howFar){
 
  DigiMouse.moveX (howFar); // modify with math for different results
  DigiMouse.delay (2);
}
 
 
void jumpBeep (int howFar) {
  //beep
  period = aSecond/freq;
  for(long k = 0; k < freq/10; k++){
    digitalWrite(piezo,HIGH);
    delayMicroseconds(period/2);
    digitalWrite(piezo,LOW);
    delayMicroseconds(period/2);
  }
   //move
  DigiMouse.moveX (howFar); // modify with math for different results
  DigiMouse.moveY (howFar); // modify with math for different results
  DigiMouse.delay (2);
  }

void jitter (int duration){
  int i = 0;
  while (i < duration){
    DigiMouse.moveX(10);
    DigiMouse.moveY(10);
    DigiMouse.delay (15);
    DigiMouse.moveX(-11);
    DigiMouse.delay (20);
    DigiMouse.moveX(10);
    DigiMouse.moveY(-10);
    DigiMouse.delay(25);
    DigiMouse.moveX(-11);
    DigiMouse.moveY(0);
    DigiMouse.delay (20);
    i++;
  }
}