Does anyone notice Keyboard.begin() Keyboard.end() not working right?

So I've been trying to set up Arduino Micro to shut off control over the keyboard after a screw up. Problem is from what I've seen it doesn't seem to care, it will allow control over the keyboard no matter what. Anyone else notice this?

How are you defining a screwup?

Where is your code?

By screw up I mean the micro kept typing “Z”.

As for code here is what I have

int clockPin = 2;
int latchPin = 3;
int dataPin = 4;
//The buttonStates array elements corralate with the following buttons on a 
//NES controller in the order they are clocked in.
//buttonStates[0] == "a"
//buttonStates[1] == "b"
//buttonStates[2] == "Select"
//buttonStates[3] == "Start"
//buttonStates[4] == "Up"
//buttonStates[5] == "Down"
//buttonStates[6] == "Left"
//buttonStates[7] == "Right"
int buttonStates [8] = {1,1,1,1,1,1,1,1};
//Use configSwitch to pick which keyboard configuration you want to use.
//ConfigSwitch == 0 is based on my configuration for Nestopia (using the nesEmulator array).
int configSwitch = 0;
//Match the elements in the arrays here with the buttonStates array to set up proper us
char nesEmulator [8] = {'z', 'x', KEY_RIGHT_SHIFT, KEY_RETURN, KEY_UP_ARROW, KEY_DOWN_ARROW, KEY_LEFT_ARROW, KEY_RIGHT_ARROW};

void setup(){
 pinMode(clockPin, OUTPUT);
 pinMode(latchPin, OUTPUT);
 pinMode(dataPin, INPUT);
 Keyboard.begin();
}

void loop(){ 
  
 readNESController();
 for(int i = 0; i<8; i++){
   if (buttonStates[i] == 0)
      Keyboard.press(keyboardSwitch(i));
   else
      Keyboard.release(keyboardSwitch(i));
 }
}

void readNESController(){
  digitalWrite(latchPin, HIGH);
  digitalWrite(latchPin, LOW);

  for(int i = 0; i < 8; i++){
    buttonStates[i] = digitalRead(dataPin);
    
    digitalWrite(clockPin, HIGH);      
    delay(.5);
    digitalWrite(clockPin, LOW);
  }  
}

char keyboardSwitch(int button){
  switch (configSwitch){
    case 0:
      return nesEmulator[button];
      break;    
  }
}

If I were to add Keyboard.end() after it .begin() it still can write to the keyboard. I was adding a button to toggle control and it didn’t work so I just tried to shut it off after starting it.

delay() only takes ints, so delay(.5) is nonsense.