Arduino Leonardo Keyboard not typing

When I upload the code for my project using the keyboard library, the Arduino gets recognized as a keyboard but it doesn’t type anything. As it says in the title I am using an Arduino Leonardo and here is my code:

#include <Keyboard.h>

void setup() {
  Keyboard.begin();
  Keyboard.press(KEY_LEFT_GUI);
  Keyboard.press('r');
  Keyboard.releaseAll();
}

void loop() {
  
}

Perhaps you are sending the keystrokes before the PC is ready to receive them. Try adding a delay between Keyboard.begin() and Keyboard.press(). I'd start at 10 seconds (10000 milliseconds) and work down from there.

Before you try a strange character like Alt-R you might want to start with a simple letter key. That way you can see if the problem is in your sketch or in how your OS interprets Alt-R.

Thank you. I did add the 10second delay and everything just worked. This is actually very unusual because I have experimented with stuff like this before and I didn't need any delay.