Arduino (leonardo) Keyboard matrix - double button press problem

Hi all,

We (a friend and I) are building a game controller. We want to use toggle switches to control games (because we will use toggle switches, when toggled, the 'key' keeps being pressed until released).

As for now, we have made a prototype setup with Arduino Leonardo and a 2x2 keyboard matrix.

The problem we are facing, is that when one button is pressed, other buttons don't work anymore.
For example: button 1 - 4 are working. But when button 1 is pressed, buttons 2 - 4 don't register anything anymore. This works for all button combinations.

Setup details
Arduino Leonardo (ATmega32u4-chip)
Solderless Breadboard with 4 buttons (with diodes preventing ghosting).
A 2 by 2 matrix, (two rows (digital input 3 and 4), two columns (digital input 6 and 7)).
Please see the attached picture for the setup.

Code

#include <Keypad.h>
#include <Keyboard.h>

const byte ROWS = 2; //two rows
const byte COLS = 2; //two columns

char keys[ROWS][COLS] = {
  {'1','2'},
  {'3','4'}
};
byte rowPins[ROWS] = {3, 4}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS); 

void setup(){
 Serial.begin(9600);
} 
void loop(){
 char customKey = customKeypad.getKey();
 if (customKey){
    //Keyboard.write("key");
    Serial.println(customKey); }

 if (customKey == '1'){
    Keyboard.write ('A');
 }

 if (customKey == '2'){
    Keyboard.write ('B');
 }

 if (customKey == '3'){
    Keyboard.write ('C');
 
 }

 if (customKey == '4'){
    Keyboard.write ('D');
  
  } 
}

Question
Can anybody help us to make our code work so that whilst one button is being pressed, a one-time signal will be forwarded to the pc (as keyboard write), another button can also be pressed and forward that respective keypress to the pc.

Which Keypad library are you using? The original library didn't support multiple keys being pressed at the same time.

PaulS:
Which Keypad library are you using? The original library didn't support multiple keys being pressed at the same time.

Hi,

Thanks for your reply!

The original (default) keyboard.h library.
Do you know any library that support multiple button presses?

sorry, real arduino noobs here.

Thanks!

PaulS:
Which Keypad library are you using? The original library didn't support multiple keys being pressed at the same time.

The new Keypad.h should support multiple keypresses. Deleted the old library and downloaded newest version. Still the same problem.

It seems that as soon as a button is pressed, the loop stopt identifying any other keys (due to the getKey). But getKeys (plural) doesnt work.

But getKeys (plural) doesnt work.

Well, bummer.

If you had posted a link to the library you are (now) using, and some code that uses that function, and some explanation of what you do and what the code ACTUALLY does, instead of saying "some code I'm not going to share doesn't do what I expect, but I'm not going to tell you what it does or what I expect", then maybe you could get something more than insincere sympathy.