Keyboard Emulator Occasionally Omits Upper Case

I'm using a SparkFun Pro Micro (ATmega32U4) as a keyboard emulator. Typing into e.g. Notepad on the PC it's perfect. Typing into a VM running on the PC it's perfect. Typing into a Remote Desktop session running from the VM, it sometimes fails to capitalise a character. e.g.

Hello There
Hello there
Hello There
Hello There
Hello There
Hello There
Hello There

The code for that is

          Keyboard.print("Hello There");
          Keyboard.write(10);  // LF

It's possible that the error never happens on the first character. Implies timing problem.

With caps-lock on, the capitalisation is reversed and the T will occasionally be incorrectly upper case.

Thanks in advance.

I've found myself a work-around.

void KbdStrByChrsPrint(char strA[]) {
  int ix = 0;
  char ch;
  while (1) {
    ch = strA[ix++];
    if (ch == 0) {break;}
    if (ch >= '\A' && ch <= '\Z') {       // if uppercase char
      ch |= 0x40;                         // convert to lowercase
      Keyboard.press(KEY_LEFT_SHIFT);     // press shift
      delay(120);                         // wait
      Keyboard.write(ch);                 // send lowercase char
      delay(120);                         // wait
      Keyboard.release(KEY_LEFT_SHIFT);   // release shift.
    } else {
      Keyboard.write(ch);
    }
  }
}

KbdStrByChrsPrint("Hello There");

I don't know how long the delays have to be. I was seeing errors with 80 mS, but not seen any so far at 120. I've also seen a # appear as a 3, so that would need some more adjustment. I don't know what the general algorithm is because I've never seen [ or ] appear as { or }.

I'm having the exact same issue with the same scenario. I never thought of doing it like this. I need to adjust this to include special characters.

Thanks!!!!

1 Like