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,181
  • 1
  • 13
  • 25
m7.arman
  • 21
  • 2
  • 1
    What keyboard layout do you have active on your PC? – chrisl Apr 14 '21 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. – timemage Apr 14 '21 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 – jsotola Apr 15 '21 at 01:18

0 Answers0