Digistump Forums
The Digispark => Digispark Libraries => Topic started by: TotallyNotKsAlt on May 03, 2017, 02:32:46 pm
-
I've been trying to get a simple keyboard prank working on my Digispark. I use the DigiKeyboard.h library to set it up, and it works for the most part.
Using the DigiKeyboard.sendkey function has me a bit confused. Can I only use one key at once? I am trying to use three at a time, and it won't work. I've tried it multiple ways, due to what other people have said. I can't find much on this and have been looking all over.
(MOD_ALT_LEFT, MOD_CONTROL_LEFT, KEY_ARROW_UP) [I modified the library to use the arrow keys] Won't work
(KEY_ARROW_UP, MOD_ALT_LEFT, MOD_CONTROL_LEFT) Somebody recommended that I put the key first. Won't work this way either.
(KEY_ARROW_UP | MOD_ALT_LEFT, MOD_CONTROL_LEFT) Saw a post claiming you have to put this operator between the mod and keys. Didn't work either.
(KEY_ARROW_UP, MOD_ALT_LEFT | MOD_CONTROL_LEFT) Did this as a combination of the last two. Didn't work either.
What am I doing wrong? I am just trying to rotate the screen (using a hotkey). Below is the full code:
_______________________________________________________________________________________________
#include "DigiKeyboard.h"
int loopn = 0;
void setup() {
// don't need to set anything up to use DigiKeyboard
}
void loop() {
if(loopn++ >= 5) {
// this is generally not necessary but with some older systems it seems to
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.sendKeyStroke(KEY_ARROW_DOWN | MOD_CONTROL_LEFT, MOD_GUI_LEFT);
DigiKeyboard.delay(1500);
DigiKeyboard.sendKeyStroke(KEY_ARROW_LEFT | MOD_CONTROL_LEFT, MOD_GUI_LEFT);
DigiKeyboard.delay(1500);
DigiKeyboard.sendKeyStroke(KEY_ARROW_RIGHT | MOD_CONTROL_LEFT, MOD_GUI_LEFT);
DigiKeyboard.delay(1500);
DigiKeyboard.sendKeyStroke(KEY_ARROW_UP | MOD_CONTROL_LEFT, MOD_GUI_LEFT);
DigiKeyboard.delay(1500);
}
}
___________________________________________________________________________________________
Thanks
-
Yup, this fixed it! Here is the source code, so others can see it:
#include "DigiKeyboard.h"
int loopn = 0;
void setup() {
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.sendKeyStroke(KEY_S, MOD_GUI_LEFT);
DigiKeyboard.delay(2000);
DigiKeyboard.println("notepad");
DigiKeyboard.delay(1000);
DigiKeyboard.sendKeyStroke(KEY_ENTER);
DigiKeyboard.delay(1500);
DigiKeyboard.println("Hello there, today we'll be flipping your screen!");
}
void loop() {
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.sendKeyStroke(KEY_ARROW_DOWN, MOD_CONTROL_LEFT | MOD_ALT_LEFT);
DigiKeyboard.delay(1500);
DigiKeyboard.sendKeyStroke(KEY_ARROW_LEFT, MOD_CONTROL_LEFT | MOD_ALT_LEFT);
DigiKeyboard.delay(1500);
DigiKeyboard.sendKeyStroke(KEY_ARROW_RIGHT, MOD_CONTROL_LEFT | MOD_ALT_LEFT);
DigiKeyboard.delay(1500);
DigiKeyboard.sendKeyStroke(KEY_ARROW_UP, MOD_CONTROL_LEFT | MOD_ALT_LEFT);
DigiKeyboard.delay(1500);
}