esp 32 bluetooth keyboard connection trouble

hi,
I don't know if I'm in the right place here but I have a problem with my esp 32 Bluetooth macro keyboard...
So my main problem is that when I want to connect the esp keyboard to my MacBook(MacBook Pro Retina 13 Zoll, early 2015) it just does not connect, it just loads for a while and then stops, but when I try it with my iPhone it works like a charm. I got it to work once but I don't know why

this is the code I wrote :

#include <BleKeyboard.h>

BleKeyboard bleKeyboard("esp 32 Macro", "lolo", 100);
const int buttonPin0 = 2;
const int buttonPin1 = 4;
const int buttonPin2 = 18;
const int buttonPin3 = 19;
const int buttonPin4 = 21;
    


int buttonState0 = 0;  
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;


int lastButtonState0 = LOW;
int lastButtonState1 = LOW;
int lastButtonState2 = LOW;
int lastButtonState3 = LOW;
int lastButtonState4 = LOW;

unsigned long lastDebounceTime0 = 0;  
unsigned long debounceDelay0 = 50;

unsigned long lastDebounceTime1 = 0;  
unsigned long debounceDelay1 = 50;

unsigned long lastDebounceTime2 = 0;  
unsigned long debounceDelay2 = 50;

unsigned long lastDebounceTime3 = 0;  
unsigned long debounceDelay3 = 50;

unsigned long lastDebounceTime4 = 0;  
unsigned long debounceDelay4 = 50;

void setup() {

 Serial.begin(115200);
 Serial.println("Starting BLE work!");
 bleKeyboard.begin();
  
  pinMode(buttonPin0, INPUT);
    pinMode(buttonPin1, INPUT);
      pinMode(buttonPin2, INPUT);
        pinMode(buttonPin3, INPUT);
          pinMode(buttonPin4, INPUT);
          
}

void loop() {
 
 
  int reading0 = digitalRead(buttonPin0);
  int reading1 = digitalRead(buttonPin1);
  int reading2 = digitalRead(buttonPin2);
  int reading3 = digitalRead(buttonPin3);
  int reading4 = digitalRead(buttonPin4);

  
if(bleKeyboard.isConnected()) {
  


if (reading0 != lastButtonState0) {
    
    lastDebounceTime0 = millis();
  }

  if (reading1 != lastButtonState1) {
    
    lastDebounceTime1 = millis();
  }

  if (reading2 != lastButtonState2) {
    
    lastDebounceTime2 = millis();
  }

  if (reading3 != lastButtonState3) {
    
    lastDebounceTime3 = millis();
  }
  
  if (reading4 != lastButtonState4) {
    
    lastDebounceTime4 = millis();
  }

  if ((millis() - lastDebounceTime0) > debounceDelay0) {
   
   
    if (reading0 != buttonState0) {
      buttonState0 = reading0;

     
      if (buttonState0 == HIGH) {
        bleKeyboard.print("2 ");
        
        Serial.println("0");
      }
    }
  }

  if ((millis() - lastDebounceTime1) > debounceDelay1) {
   
   
    if (reading1 != buttonState1) {
      buttonState1 = reading1;

     
      if (buttonState1 == HIGH) {
        bleKeyboard.print("4 ");
        Serial.println("1");
      }
    }
  }

  if ((millis() - lastDebounceTime2) > debounceDelay2) {
   
   
    if (reading2 != buttonState2) {
      buttonState2 = reading2;

     
      if (buttonState2 == HIGH) {
        bleKeyboard.write(KEY_LEFT_GUI);
        bleKeyboard.print("z");
        Serial.println("2");
      }
    }
  }

  if ((millis() - lastDebounceTime3) > debounceDelay3) {
   
   
    if (reading3 != buttonState3) {
      buttonState3 = reading3;

     
      if (buttonState3 == HIGH) {
        bleKeyboard.print("19 ");
        Serial.println("3");
      }
    }
  }

  if ((millis() - lastDebounceTime4) > debounceDelay4) {
   
   
    if (reading4 != buttonState4) {
      buttonState4 = reading4;

     
      if (buttonState4 == HIGH) {
        bleKeyboard.print("21 ");
        Serial.println("4");
      }
    }
  }

 
   lastButtonState0 = reading0;
    lastButtonState1 = reading1;
     lastButtonState2 = reading2;
      lastButtonState3 = reading3;
       lastButtonState4 = reading4;
 }
}

like is said I don't know if I am in the right place here but maybe someone has head the same problem and can help me.

best regards, Lorenz :smiley: