How to separate two key into independent keypresses

Im pretty new to this, just bought an arduino yesterday to make a 2 key keyboard to play osu, i know nothing about coding so I have a pretty stupid question. I follow the instruction to make this code:

#include <Keyboard.h>

void setup() {
  
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
 
  Keyboard.begin();
}

void loop() {
  while (digitalRead(4) == HIGH) {
 
    delay(10);
  }
  delay(10);
  
  Keyboard.press('x');
  delay(10);
  Keyboard.release('x');
  
  delay(10);

   while (digitalRead(5) == HIGH) {

    delay(10);
  }
  delay(10);

  Keyboard.press('z');
  delay(10);
  Keyboard.release('z');

  delay(10);
}

So when i presses the button it does register and enter the key but I have to press the 2nd key in order for the 1st key to be able to use again. So my question here is how to separate these two keys so that i can press one key twice without having to press the other key 1st. I know its a dumb question but im new here and i need some help so please help me, I'd be very thankfull

Get rid of the while loops and use if instead. i.e. if digitalRead returns LOW, do the keyboard stuff associated with the pin you read.

well now it just loops x and z

Post your new code.

#include <Keyboard.h>

void setup() {

pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);

Keyboard.begin();
}

void loop() {
if (digitalRead(4) == HIGH) {

delay(10);
}
delay(10);

Keyboard.press('x');
delay(10);
Keyboard.release('x');

delay(10);

if (digitalRead(5) == HIGH) {

delay(10);
}
delay(10);

Keyboard.press('z');
delay(10);
Keyboard.release('z');

delay(10);
}

Rather than this:

if (digitalRead(4) == HIGH) {
 
    delay(10);
  }
  delay(10);
  
  Keyboard.press('x');
  delay(10);
  Keyboard.release('x');
  
  delay(10);

Try:

if (digitalRead(4) == LOW) {
 
  delay(10);
  
  Keyboard.press('x');
  delay(10);
  Keyboard.release('x');
  
  delay(10);
}

Oh it worked now thanks lol

one more question how do you make it so that when you hold the key it stays active not looping

Not sure what you mean by that.

Its kinda hard to explain. On a normal keyboard when you press a button it only register 1 keypresses but on the Arduino when you presses it it just loops the action instead of holding it

nvm i figured it out just need to separate the keyboard.release from the keyboard.press with an if statement XD