Beginner Arduino User - Need help with multiple buttons

Hi guys. I'm a complete novice when it comes to arduinos. I'm using it for a college project and I'm having what I suppose would be a simple fix for anyone who had a clue about arduinos.
Basically, I'm using an Arduino Leonardo to write keyboard presses when a button is pushed. I can make 1 button work at a time, but not two. I'm assuming this is a problem with my code, as I'm merely copying and pasting it to try make the second one work.

The second button is set up identical to the first, and I can get input from it when the original code is set to Pin 5, but I can't get any further than that!
Any help would be greatly appreciated!

Probably a code issue. Would love to help but you didn’t give me much of a chance since I can’t see the code.

Bombadalf:
as I’m merely copying and pasting it to try make the second one work.

Would be much more effective to spend some time learning how it works. You’d have this licked in no time. Hack and paste coding just leads to this very sort of frustration.

Try this...
Although I do see possible design flaws. You should set your buttons to INPUT_PULLUP, and when you press the button, it should ground it. Otherwise, if your arduino pin is not grounded when the button is not pressed, you end up with a floating pin and you will get random values.

Another design flaw would be that you should debounce your button readings. Basically when you press a button, it is not simply NOT PRESSED then PRESSED, it oscillates very quickly before settling on its final value. There are some examples on how to solve this problem, however, a very crude method would be to simply add a small delay at the end of your code.

const byte buttonPin1 = 5;
const byte buttonPin2 = 6;
boolean previousButtonState1 = HIGH;
boolean previousButtonState2 = HIGH;

void setup() {
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  
  Keyboard.begin();
}

void loop() {
  boolean buttonState1 = digitalRead(buttonPin1);
  boolean buttonState2 = digitalRead(buttonPin2);
  
  if(buttonState1 != previousButtonState1 && buttonState1 == HIGH) {
    Keyboard.write('1');
  }
  if(buttonState2 != previousButtonState2 && buttonState2 == HIGH) {
    Keyboard.write('2');
  }
  previousButtonState1 = buttonState1;
  previousButtonState2 = buttonState2;
}