Custom Professional Game Pad Code Help Teensy 3.2

So I am trying to replace a Logitech G13 with a creation of my own.

It will be used for gaming only on a PC. The G13 thumb stick can be used as a joystick or as 8 way keyboard input. I dont want any fancy stuff like an lcd or profile starage.

I am using a Teensy 3.2 , a Chinese pcb mounted thumb stick from Amazon, and Gateron 3 pin (which have 2 pins) linear black mechanical switches.

I want 21 keyboard inputs and an analog thumb stick that can be used as a joystick or keyboard input.
I have a 6 pin toggle switch that will give the thumb stick access to 4 pin on the Teensy 2 at a time.

I am a brick layer and an a little lost when it comes to coding but I am no slouch when it comes to soldering.
so far I have the keyboard part coded in an array that I basically copied from here
I used the Joystick example for the analog read, but whre do I go from here :smiley-eek

I found this but It looks messy to me, could I use another array?

Also, I know that using a matrix is what is typically done for keyboard input and that the Teensy 3.2 is overkill... but it has the pins to do it this way... am I loosing out on anything? Besides money...

#include <Keyboard.h>

int led = 13;
int timer = 1;

const int pinBtn1 = 0;
const int pinBtn2 = 1;
const int pinBtn3 = 2;
const int pinBtn4 = 3;
const int pinBtn5 = 4;
const int pinBtn6 = 5;
const int pinBtnTAB = 6;
const int pinBtnZ = 7;
const int pinBtnQ = 8;
const int pinBtnE = 9;
const int pinBtnF = 10;
const int pinBtnT = 11;
const int pinBtnSH = 12;
const int pinBtnX = 18;
const int pinBtnC = 19;
const int pinBtnV = 20;
const int pinBtnSP = 21;
const int pinBtnCTRL = 22;
const int pinBtnB = 23;
const int pinBtnG = 24;
const int pinBtnN = 25;
const int pinBtnENT = 28;

const byte BUTTON_PINS[] = {pinBtn1,pinBtn2, pinBtn3,pinBtn4, pinBtn5, pinBtn6, pinBtnTAB, pinBtnZ, pinBtnQ, pinBtnE, pinBtnF, pinBtnT, pinBtnSH, pinBtnX, pinBtnC, pinBtnV, pinBtnSP, pinBtnCTRL, pinBtnB, pinBtnG, pinBtnN, pinBtnENT};
const int NUMBUTTONS = sizeof BUTTON_PINS / sizeof BUTTON_PINS[0];
const short KEY_CODES[NUMBUTTONS] = {KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_TAB, KEY_Z, KEY_Q, KEY_E, KEY_F, KEY_T, MODIFIERKEY_LEFT_SHIFT, KEY_X, KEY_C, KEY_V, KEY_SPACE, MODIFIERKEY_LEFT_CTRL, KEY_B, KEY_G, KEY_N, KEY_ENTER};
byte PreviousButtonState[NUMBUTTONS];

int xVal = 0;
int yVal = 0;



void setup() { 

for (byte i = 0; i < NUMBUTTONS; i++) {
  pinMode(BUTTON_PINS[i], INPUT_PULLUP);
  PreviousButtonState[i] = HIGH;
}
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
}

void loop() {


Joystick.X(analogRead(A0));
Joystick.Y(analogRead(A1));



for (byte i=0; i<NUMBUTTONS; i++) {
 byte buttonState = digitalRead(BUTTON_PINS[i]);
 if (buttonState != PreviousButtonState[i]){
  PreviousButtonState[i] = buttonState;
  if (buttonState) {
    Keyboard.release(KEY_CODES[i]);
    delay(timer);
  } else {
    Keyboard.press(KEY_CODES[i]);
    delay(timer);
  }
 }
}




}

It looks very nice to me so far. I would recommend that you use the Auto Format feature (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor), since this will make it easier for you to see the structure of your code and spot bugs.

If I understand your question, the part you're asking for help with now is to do the joystick. Is that correct?

I don't understand the part about using the joystick as a keyboard input. Which keypresses is the joystick supposed to trigger?

Thank you for the tip!

Some games only accept key stroke for directional movement others accept joystick input, I would like to play all games the same way with the same equipment.

I seem to have figured it out.... but can I get some feed back on it?
Is this code efficient?
I am worried about CPU usage and input lag.

int led = 13;

int timer = 1;

const int dedznX = 1000;
const int dedznY = 24;
const int pinBtn1 = 0;
const int pinBtn2 = 1;
const int pinBtn3 = 2;
const int pinBtn4 = 3;
const int pinBtn5 = 4;
const int pinBtn6 = 5;
const int pinBtnTAB = 6;
const int pinBtnZ = 7;
const int pinBtnQ = 8;
const int pinBtnE = 9;
const int pinBtnF = 10;
const int pinBtnT = 11;
const int pinBtnSH = 12;
const int pinBtnX = 18;
const int pinBtnC = 19;
const int pinBtnV = 20;
const int pinBtnSP = 21;
const int pinBtnCTRL = 22;
const int pinBtnB = 23;
const int pinBtnG = 24;
const int pinBtnN = 25;
const int pinBtnENT = 28;

int valX = analogRead(A2);
int valY = analogRead(A3);

const byte BUTTON_PINS[] = {pinBtn1, pinBtn2, pinBtn3, pinBtn4, pinBtn5, pinBtn6, pinBtnTAB, pinBtnZ, pinBtnQ, pinBtnE, pinBtnF, pinBtnT, pinBtnSH, pinBtnX, pinBtnC, pinBtnV, pinBtnSP, pinBtnCTRL, pinBtnB, pinBtnG, pinBtnN, pinBtnENT};
const int NUMBUTTONS = sizeof BUTTON_PINS / sizeof BUTTON_PINS[0];
const short KEY_CODES[NUMBUTTONS] = {KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_TAB, KEY_Z, KEY_Q, KEY_E, KEY_F, KEY_T, MODIFIERKEY_LEFT_SHIFT, KEY_X, KEY_C, KEY_V, KEY_SPACE, MODIFIERKEY_LEFT_CTRL, KEY_B, KEY_G, KEY_N, KEY_ENTER};
byte PreviousButtonState[NUMBUTTONS];

void setup() {

  for (byte i = 0; i < NUMBUTTONS; i++) {
    pinMode(BUTTON_PINS[i], INPUT_PULLUP);
    PreviousButtonState[i] = HIGH;
  }
  pinMode(A0, INPUT_PULLUP);
  pinMode(A1, INPUT_PULLUP);

  pinMode(A2, INPUT_PULLUP);
  pinMode(A3, INPUT_PULLUP);
}

void loop() {

  Joystick.X(analogRead(A0));
  Joystick.Y(analogRead(A1));

  int valX = analogRead(A2);
  int valY = analogRead(A3);

  if (valX > dedznY) {
    Keyboard.release(KEY_W);
    delay(timer);
  } else {
    Keyboard.press(KEY_W);
    delay(timer);
  }
  if (valX < dedznX) {
    Keyboard.release(KEY_S);
    delay(timer);
  } else {
    Keyboard.press(KEY_S);
    delay(timer);
  }
  if (valY > dedznY) {
    Keyboard.release(KEY_A);
    delay(timer);
  } else {
    Keyboard.press(KEY_A);
    delay(timer);
  }
  if (valY < dedznX) {
    Keyboard.release(KEY_D);
    delay(timer);
  } else {
    Keyboard.press(KEY_D);
    delay(timer);
  }


  for (byte i = 0; i < NUMBUTTONS; i++) {
    byte buttonState = digitalRead(BUTTON_PINS[i]);
    if (buttonState != PreviousButtonState[i]) {
      PreviousButtonState[i] = buttonState;
      if (buttonState) {
        Keyboard.release(KEY_CODES[i]);
        delay(timer);
      } else {
        Keyboard.press(KEY_CODES[i]);
        delay(timer);
      }
    }
  }

}