Teensy 3.2 Keyboard code HELP!

In this code everything works until i get to this row Keyboard.set_key7( KEY_D ); and i think its because of typedef void KeyFunction_t(uint8_t c);. So íf someone could help me with adding more keys to my keyboard i would very much appriciate it!

const int pinBtnQ = 0;
const int pinBtnW = 1;
const int pinBtnE = 2;
const int pinBtnR = 3;
const int pinBtnA = 4;
const int pinBtnS = 5;
const int pinBtnD = 6;
const int pinBtnF = 7;
const int pinLEDOutput = 11;

//Variables for the states of the SNES buttons
byte buttons[] = {pinBtnQ, pinBtnW, pinBtnE, pinBtnR, pinBtnA, pinBtnS, pinBtnD, pinBtnF
};
short keys [] = {KEY_Q, KEY_W, KEY_E, KEY_R, KEY_A, KEY_S, KEY_D, KEY_F};

#define NUMBUTTONS sizeof(buttons)
typedef void KeyFunction_t(uint8_t c);

KeyFunction_t* buttonActive[NUMBUTTONS];
KeyFunction_t* keyList[] = {};
int            keySlot = sizeof(keyList) / sizeof(KeyFunction_t*);

void setup()
{
 //Setup the pin modes.
 pinMode( pinLEDOutput, OUTPUT );
 //Special for the Teensy is the INPUT_PULLUP
 //It enables a pullup resitor on the pin.
for (byte i=0; i< NUMBUTTONS; i++) {
 pinMode(buttons[i], INPUT_PULLUP );
}
 //Zero the SNES controller button keys:

}


void loop()
{
//  //debugging the start button...
 digitalWrite ( pinLEDOutput, digitalRead(pinBtnQ));

 //Progess the SNES controller buttons to send keystrokes.
 fcnProcessButtons();
 
}

//Function to process the buttons from the SNES controller
void fcnProcessButtons()
{
 //Assign temporary values for the buttons.
 //Remember, the SNES buttons are read as active LOW.
 //Capture their status here:
 boolean boolBtnQ = !digitalRead(pinBtnQ);
 boolean boolBtnW = !digitalRead(pinBtnW);
 boolean boolBtnE = !digitalRead(pinBtnE);
 boolean boolBtnR = !digitalRead(pinBtnR);
 boolean boolBtnA = !digitalRead(pinBtnA);
 boolean boolBtnS = !digitalRead(pinBtnS);
 boolean boolBtnD = !digitalRead(pinBtnD);
 boolean boolBtnF = !digitalRead(pinBtnF);
 if ( boolBtnQ )
 {
   //Set key1 to the Q key
   Keyboard.set_key1( KEY_Q );
 } else {
   Keyboard.set_key1( 0 );
 }
if ( boolBtnW )
 {
   Keyboard.set_key2( KEY_W );
 }    else{
     Keyboard.set_key2( 0 );
   }
   if ( boolBtnE )
 {
   Keyboard.set_key3( KEY_E );
 } else {
   Keyboard.set_key3( 0 );
   }
       if ( boolBtnR )
 {
   Keyboard.set_key4( KEY_R );
 } else {
   Keyboard.set_key4( 0 );
   }
 if ( boolBtnA )
 {
   
   Keyboard.set_key5( KEY_A );
 } else {
   Keyboard.set_key5( 0 );
 }
if ( boolBtnS )
 {
   Keyboard.set_key6( KEY_S );
 }    else{
     Keyboard.set_key6( 0 );
   }
   if ( boolBtnD )
 {
   Keyboard.set_key7( KEY_D );
 } else {
   Keyboard.set_key7( 0 );
   }
       if ( boolBtnF )
 {
   Keyboard.set_key8( KEY_F );
 } else {
   Keyboard.set_key8( 0 );
   }
 //Send all of the set keys.
 Keyboard.send_now();
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

In this code everything works until i get to this row Keyboard.set_key7( KEY_D )

What happens then?

i think its because of typedef void KeyFunction_t(uint8_t c);

You'd be wrong. That statement just defines that KeyFunction_t is a type (pointer to function) that takes one argument of type char, and returns nothing.

What happens then?
You'd be wrong. That statement just defines that KeyFunction_t is a type (pointer to function) that takes one argument of type char, and returns nothing.

To be honest im not very experiensed in programming, hehe. But all the buttons works to Keyboard.set_key6( KEY_S ); and after that it's like the set_key7 isn't getting recognized! All the other set_key are orange color but at 7 it becomes black color.

To be honest im not very experiensed in programming, hehe. But all the buttons works to Keyboard.set_key6( KEY_S ); and after that it's like the set_key7 isn't getting recognized! All the other set_key are orange color but at 7 it becomes black color.

How many keys does a SNES controller have? Six, apparently. You can't emulate more keys than the device has.

set_key7() and set_key8() don't exist.
The maximum number of keys pressed at the same time is 6 + modifiers.

https://www.pjrc.com/teensy/td_keyboard.html

Why are you using the set_key functions anyway? Just use press() and release() and let the library keep track of which keys are pressed.

So i still need help! I need help with programming my code so i can use more than 6 buttons for my keyboard. The code is mainly from a SNES controller and i need to change that so i can have atleast 10 buttons! I’m really new to programming and would really appriciate it if anyone could help with this!The code works just fine until i try to add my 7th button [Keyboard.set_key7( KEY_D );]. Any help is much appriciated!

Thanks in advance!

const int pinBtnQ = 0;
const int pinBtnW = 1;
const int pinBtnE = 2;
const int pinBtnR = 3;
const int pinBtnA = 4;
const int pinBtnS = 5;
const int pinBtnD = 6;
const int pinBtnF = 7;
const int pinLEDOutput = 11;

//Variables for the states of the buttons
byte buttons[] = {pinBtnQ, pinBtnW, pinBtnE, pinBtnR, pinBtnA, pinBtnS, pinBtnD, pinBtnF
};
short keys [] = {KEY_Q, KEY_W, KEY_E, KEY_R, KEY_A, KEY_S, KEY_D, KEY_F};

#define NUMBUTTONS sizeof(buttons)
typedef void KeyFunction_t(uint8_t c);

KeyFunction_t* buttonActive[NUMBUTTONS];
KeyFunction_t* keyList[] = {};
int            keySlot = sizeof(keyList) / sizeof(KeyFunction_t*);

void setup()
{
//Setup the pin modes.
pinMode( pinLEDOutput, OUTPUT );
//Special for the Teensy is the INPUT_PULLUP
//It enables a pullup resitor on the pin.
for (byte i=0; i< NUMBUTTONS; i++) {
pinMode(buttons[i], INPUT_PULLUP );
}
//Zero the controller button keys:

}


void loop()
{
//  //debugging the start button...
digitalWrite ( pinLEDOutput, digitalRead(pinBtnQ));

//Progess the controller buttons to send keystrokes.
fcnProcessButtons();

}

//Function to process the buttons from the controller
void fcnProcessButtons()
{
//Assign temporary values for the buttons.
//Remember, the buttons are read as active LOW.
//Capture their status here:
boolean boolBtnQ = !digitalRead(pinBtnQ);
boolean boolBtnW = !digitalRead(pinBtnW);
boolean boolBtnE = !digitalRead(pinBtnE);
boolean boolBtnR = !digitalRead(pinBtnR);
boolean boolBtnA = !digitalRead(pinBtnA);
boolean boolBtnS = !digitalRead(pinBtnS);
boolean boolBtnD = !digitalRead(pinBtnD);
boolean boolBtnF = !digitalRead(pinBtnF);
if ( boolBtnQ )
{
  //Set key1 to the Q key
  Keyboard.set_key1( KEY_Q );
} else {
  Keyboard.set_key1( 0 );
}
if ( boolBtnW )
{
  Keyboard.set_key2( KEY_W );
}    else{
    Keyboard.set_key2( 0 );
  }
  if ( boolBtnE )
{
  Keyboard.set_key3( KEY_E );
} else {
  Keyboard.set_key3( 0 );
  }
      if ( boolBtnR )
{
  Keyboard.set_key4( KEY_R );
} else {
  Keyboard.set_key4( 0 );
  }
if ( boolBtnA )
{
  
  Keyboard.set_key5( KEY_A );
} else {
  Keyboard.set_key5( 0 );
}
if ( boolBtnS )
{
  Keyboard.set_key6( KEY_S );
}    else{
    Keyboard.set_key6( 0 );
  }
  if ( boolBtnD )
{
  Keyboard.set_key7( KEY_D );
} else {
  Keyboard.set_key7( 0 );
  }
      if ( boolBtnF )
{
  Keyboard.set_key8( KEY_F );
} else {
  Keyboard.set_key8( 0 );
  }
//Send all of the set keys.
Keyboard.send_now();


}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

@lurreg, please do not cross-post. Threads merged.

I believe the library only allows you to have 6 keys pressed at one time. If you use the .press() and .release() when your buttons are pressed and released the Keyboard library will keep track of which key is using which of the six available entries.

Rather than repeating code for each button you should be using arrays:

#include <Keyboard.h>
const int pinBtnQ = 0;
const int pinBtnW = 1;
const int pinBtnE = 2;
const int pinBtnR = 3;
const int pinBtnA = 4;
const int pinBtnS = 5;
const int pinBtnD = 6;
const int pinBtnF = 7;
const int pinLEDOutput = 11;

const byte BUTTON_PINS[] = {pinBtnQ, pinBtnW, pinBtnE, pinBtnR, pinBtnA, pinBtnS, pinBtnD, pinBtnF};
const int NUMBUTTONS = sizeof BUTTON_PINS / sizeof BUTTON_PINS[0];
// Teensy:
const short KEY_CODES[NUMBUTTONS] = {KEY_Q, KEY_W, KEY_E, KEY_R, KEY_A, KEY_S, KEY_D, KEY_F};
// Arduino Leonardo:
// const char KEY_CODES[] = "qwerasdf";

byte PreviousButtonState[NUMBUTTONS];  // Defauts to LOW/0/false

void setup() {
  //Setup the pin modes.
  pinMode( pinLEDOutput, OUTPUT );

  for (byte i = 0; i < NUMBUTTONS; i++) {
    pinMode(BUTTON_PINS[i], INPUT_PULLUP );
    PreviousButtonState[i] = HIGH; // Reads HIGH when not pressed
  }
}

void loop() {
  // Check all the buttons
  for (byte i=0; i<NUMBUTTONS; i++) {
    byte buttonState = digitalRead(BUTTON_PINS[i]);
    if (buttonState != PreviousButtonState[i]) {
      // STATE HAS CHANGED
      PreviousButtonState[i] = buttonState;
      if (buttonState) {
        // HIGH == Not Pressed
        Keyboard.release(KEY_CODES[i]);
      } else {
        // LOW == Pressed
        Keyboard.press(KEY_CODES[i]);
      }
    }
  }
}