Trying to program multiple buttons for a keyboard

I told you that there was a better way !

And there definitely was now to learn some more and grow on this as time goes

No problem. I hope you understand the changes I made well enough to use the same technique in the future. If not, please ask any questions.

Hello mbishopfof

One solution using OOP is missing in this thread.

You can rearrange the used button and related letter simply.

constexpr int ButtonPin[] {A0, A1, A2, A3, A4, A5, A6, A7};
constexpr char Button2Char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};

The compiler is a clever and smart guy to generate a running sketch out of the edited settings for button and related letter.
That´s cool.

Check, try, play and have fun:

/* BLOCK COMMENT
  - https://forum.arduino.cc/t/trying-to-program-multiple-buttons-for-a-keyboard/1102330
  - Trying to program multiple buttons for a keyboard
  - This sketch may contain traces of C++.
  - In case of indisposition:
  - https://www.learncpp.com/
  - Hardware:
  - Thanks to LarryD
  - https://europe1.discourse-cdn.com/arduino/original/4X/7/e/0/7e0ee1e51f1df32e30893550c85f0dd33244fb0e.jpeg
  - Tested @ Arduino: DUE[X] - UNO [ ] - Nano [ ]
*/
#define ProjectName "Trying to program multiple buttons for a keyboard"

// I am too lazy to type
#define usl unsigned long
// include libaries
#include <Keyboard.h>
// make variables
constexpr int ButtonPin[] {A0, A1, A2, A3, A4, A5, A6, A7};
constexpr char Button2Char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
// make structures
struct TIMER
{
  usl now;
  usl  span;
  int onOff;
};
struct BUTTON2CHAR
{
  int pin;
  char letter;
  int stateOld;
  TIMER debounce;
  TIMER release;
  void make (int pin_, char letter_)
  {
    pin = pin_;
    pinMode(pin, INPUT_PULLUP);
    letter = letter_;
    stateOld = LOW;
    debounce.now = millis();
    debounce.span = 20;
    release.now = millis();
    release.span = 50;
    release.onOff = LOW;
  }
};
BUTTON2CHAR button2Chars[sizeof(ButtonPin) / sizeof(ButtonPin[0])];
// tools
void heartBeat(int LedPin)
{
  static bool setUp = false;
  if (!setUp) pinMode (LedPin, OUTPUT), setUp = !setUp;
  digitalWrite(LedPin, (millis() / 500) % 2);
}
void setup()
{
  Serial.begin(115200);
  Serial.print(ProjectName), Serial.print(" in "), Serial.println(__FILE__);
  int element = 0;
  for (auto &button2Char : button2Chars) button2Char.make(ButtonPin[element], Button2Char[element]), element++;
  Keyboard.begin();
}
void loop()
{
  usl currentMillis = millis();
  heartBeat(LED_BUILTIN);
  for (auto &button2Char : button2Chars)
  {
    if (currentMillis - button2Char.debounce.now >= button2Char.debounce.span)
    {
      button2Char.debounce.now = currentMillis;
      int stateNew = digitalRead(button2Char.pin) ? LOW : HIGH;
      if (button2Char.stateOld != stateNew)
      {
        button2Char.stateOld = stateNew;
        if (stateNew == HIGH)
        {
          Keyboard.press(button2Char.letter);
          button2Char.release.now = currentMillis;
          button2Char.release.onOff = HIGH;
        }
      }
    }
    if (currentMillis - button2Char.release.now >= button2Char.release.span && button2Char.release.onOff == HIGH)
    {
      button2Char.release.onOff = LOW;
      Keyboard.release(button2Char.letter);
    }
  }
}

Have a nice day and enjoy coding in C++.

p.s. All buttons are connected to gnd.