0

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:
}
asked Apr 6, 2017 at 18:23

3 Answers 3

1

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);`
answered Apr 6, 2017 at 18:42
0
1

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);
answered Oct 3, 2022 at 23:11
1
  • Please enhance your answer: Correct the typo in "cmd". Add some words what is different to the existing code. Commented Oct 4, 2022 at 6:28
-1

Please use DigiKeyboard.print(cmd);

answered Oct 28, 2020 at 20:03
1
  • 1
    And why do you think that will open CMD in administrator mode? Commented Oct 28, 2020 at 20:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.