Emulate keyboard with keyboard.h

I am trying to make an Arduino to type some pre programmed text, but it doesn't type anything on the target windows computer. It is known that the code is working since it is working fine on my Mac. What could cause this? I am guessing that the driver for the HID can't be found.Which could be solved by emulating the device as a known keyboard with driver already installed. The code is:

/*
Copyright (c) 2017 Seytonic, Spacehuhn (Licensed under MIT)
For more information see: github.com/seytonic/malduino
*/

#include "Keyboard.h"
#include "Mouse.h"

#define blinkInterval 50
#define ledPin 3
#define buttonPin 2

int defaultDelay = 4;
int defaultCharDelay = 5;
int rMin = 0;
int rMax = 100;

bool ledOn = true;

void typeKey(int key){
  Keyboard.press(key);
  delay(defaultCharDelay);
  Keyboard.release(key);
}

void setup(){
  
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  
  if(digitalRead(buttonPin) == LOW){
    
    Keyboard.begin();
    Mouse.begin();
    
    /* ----- Begin-Script -----*/
    
    /* [Parsed By Duckuino (Licensed under MIT) - for more information visit: https://github.com/Nurrl/Dckuino.js] */    
    delay(1000);

    delay(defaultDelay);
    Keyboard.print("Text goes here");
    
    /* ----- End-Script -----*/
    
    Keyboard.end();
  }
}

void loop(){
  ledOn = !ledOn;
  digitalWrite(ledPin, ledOn);
  delay(blinkInterval);
}

Edit: it is a Arduino Leonardo compatible board with the atmega32u4

Why is all the keyboard stuff in setup()? Unless you are pressing the switch at the time the Arduino starts up, nothing will be sent.

PaulS:
Why is all the keyboard stuff in setup()? Unless you are pressing the switch at the time the Arduino starts up, nothing will be sent.

That is intended as this way I can make sure that I don't trigger the code when I want to program the Arduino board.

How long does it take to register the keyboard on Windows? delay(1000) might not be enough.

oqibidipo:
How long does it take to register the keyboard on Windows? delay(1000) might not be enough.

let me try to increase that. I will report back when I could try it, since I am not next to the target computer.

oqibidipo:
How long does it take to register the keyboard on Windows? delay(1000) might not be enough.

Ok, I found out that it takes around 10 to 20 seconds to install the driver, but I want to remove that wait by making it to emulate another keyboard that already have the driver installed