I am quite new to Arduino and DigiSparkKeyboard so I don't know much about them. I am trying to get by DigiSpark to open CMD in administrator mode but it just doesn't work. I know that I need to get it to press control, shift and enter at the same time in order for it to run as administrator but it doesn't work. At the moment my code looks like:
#include "DigiKeyboard.h"
#define MOD_SHIFT_LEFT (1<<1) //00000010
#define MOD_GUI_LEFT (1<<3) //00001000
#define MOD_CONTROL_LEFT 1
#define KEY_ENTER 40
#define KEY_C 6
#define KEY_M 16
#define KEY_D 7
void setup() {
// put your setup code here, to run once:
DigiKeyboard.update();
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.sendKeyStroke(0, MOD_GUI_LEFT);
DigiKeyboard.delay(1000);
DigiKeyboard.sendKeyStroke(KEY_C);
DigiKeyboard.sendKeyStroke(KEY_M);
DigiKeyboard.sendKeyStroke(KEY_D);
DigiKeyboard.delay(1000);
DigiKeyboard.sendKeyStroke(MOD_CONTROL_LEFT + MOD_SHIFT_LEFT + KEY_ENTER);
}
void loop() {
// put your main code here, to run repeatedly:
}
3 Answers 3
Looking at the code, the first argument should be the key, and the second the modifiers. So DigiKeyboard.sendKeyStroke(MOD_CONTROL_LEFT + MOD_SHIFT_LEFT + KEY_ENTER);
should become:
DigiKeyboard.sendKeyStroke(KEY_ENTER, MOD_CONTROL_LEFT + MOD_SHIFT_LEFT);`
You can use this code :
Explanation of the code
Opens the side menu, then searches for CMD, then right-click on it to open it as administrator A window will appear Open as administrator Yes or No It will go to the Yes button
DigiKeyboard.sendKeyStroke(0, MOD_GUI_LEFT);
DigiKeyboard.delay(1500);
DigiKeyboard.print("c;d");
DigiKeyboard.delay(1500);
DigiKeyboard.sendKeyStroke(KEY_ENTER, MOD_CONTROL_LEFT | MOD_SHIFT_LEFT);
DigiKeyboard.delay(1000);
DigiKeyboard.sendKeyStroke(0);
DigiKeyboard.sendKeyStroke(KEY_ARROW_LEFT);
DigiKeyboard.delay(500);
DigiKeyboard.sendKeyStroke(KEY_ENTER);
-
Please enhance your answer: Correct the typo in "cmd". Add some words what is different to the existing code.the busybee– the busybee2022年10月04日 06:28:03 +00:00Commented Oct 4, 2022 at 6:28
Please use DigiKeyboard.print(cmd);
-
1And why do you think that will open CMD in administrator mode?sempaiscuba– sempaiscuba2020年10月28日 20:31:05 +00:00Commented Oct 28, 2020 at 20:31