2

I want to open notepad by my Digispark. I use this code:

/* * Generated with <3 by Dckuino.js, an open source project ! */
#include <avr/pgmspace.h>
#include "DigiKeyboard.h"
const char line1[] PROGMEM = "notepad.exe";
const char line2[] PROGMEM = "Hello World!";
char buffer[256];
#define GetPsz(x) (strncpy_P(buffer, (char*)x, 256))
#define KEY_UP_ARROW 0x52
#define KEY_DOWN_ARROW 0x51
#define KEY_LEFT_ARROW 0x50
#define KEY_RIGHT_ARROW 0x4F
#define KEY_LEFT_GUI 0xE3
#define KEY_ESC 0x29
#define KEY_TAB 0x2B
void digiBegin() {
 DigiKeyboard.sendKeyStroke(0,0);
 DigiKeyboard.delay(50);
}
void digiEnd() {
 const int led=1;
 pinMode(led, OUTPUT);
 while (1) {
 digitalWrite(led, !digitalRead(led));
 DigiKeyboard.delay(1000);
 }
}
void printText(char *txt) {
 DigiKeyboard.print(txt);
 DigiKeyboard.update();
}
void setup() {
 digiBegin();
 DigiKeyboard.sendKeyStroke(KEY_R,MOD_GUI_LEFT);
 DigiKeyboard.delay(50);
 // notepad.exe printText(GetPsz(line1));
 DigiKeyboard.sendKeyStroke(KEY_ENTER);
 DigiKeyboard.delay(100);
 // Hello World! printText(GetPsz(line2));
 digiEnd();
} /* Unused endless loop */ void loop() {}

My program opened RUN Windows, but instead of typing "notepad.exe" it types "fgl]hY&]p]" and I don't know where am I am making mistakes. Please help me.

I have to write my code similar this:

#include "DigiKeyboard.h"
int pinled = 1;
void setup()
{
 pinMode(3, INPUT);
 digitalWrite(3, HIGH);
}
void loop()
{
 DigiKeyboard.sendKeyStroke(0);
 if(digitalRead(3) == LOW)
 {
 DigiKeyboard.sendKeyPress(KEY_R, MOD_GUI_LEFT);
 DigiKeyboard.delay(10);
 DigiKeyboard.sendKeyStroke(0, 0);
 DigiKeyboard.sendKeyStroke(KEY_C);
 DigiKeyboard.sendKeyStroke(KEY_M);
 DigiKeyboard.sendKeyStroke(KEY_D);
 DigiKeyboard.sendKeyStroke(KEY_ENTER);
 DigiKeyboard.delay(500);
 DigiKeyboard.sendKeyStroke(KEY_I);
 DigiKeyboard.sendKeyStroke(KEY_P);
 DigiKeyboard.sendKeyStroke(KEY_C);
 DigiKeyboard.sendKeyStroke(KEY_O);
 DigiKeyboard.sendKeyStroke(KEY_N);
 DigiKeyboard.sendKeyStroke(KEY_F);
 DigiKeyboard.sendKeyStroke(KEY_I);
 DigiKeyboard.sendKeyStroke(KEY_G);
 DigiKeyboard.sendKeyStroke(KEY_ENTER);
 }
}
timemage
5,6391 gold badge14 silver badges25 bronze badges
asked Apr 14, 2021 at 18:16
3
  • 1
    What keyboard layout do you have active on your PC? Commented Apr 14, 2021 at 19:42
  • I tried to clean up the question a bit. You have // notepad.exe printText(GetPsz(line1));, but I'm guessing these are two separate lines in the code you're actually running; likewise for line2. Commented Apr 14, 2021 at 20:29
  • when debugging code like yours, always print strings like 1111122222233333 or aaabbbccc .... that way you can tell if characters repeat, even if they are the wrong characters ... in your example, one character appears to repeat, but it us uncertain Commented Apr 15, 2021 at 1:18

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

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.