Problems with CustomKeypad

Hello everyone,

I'm quite new to the wondrous world of arduino. Lately I have been working on making a custom macropad using an arduino pro micro and some buttons. I'm planning to use this to press keycombinations to use in a flight sim (DCS in particular) I ran onto some problems. While testing it seems that some of my buttons are always passing through electricity. Now these buttons are registering when I am not pressing them. Is there a way to reverse this, codingwise I mean. Or do I just have to buy new buttons? My other problem is that sometimes the buttons that do work don't 'emit' the keypresses I want, they don't show up, if you know what I mean. The buttons that don't work at all are the ones labeled C, D and F. Can you help me?

Here you can find my broken code, I deleted some parts of the code for the buttons that don't work. --> the typing part

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

const byte ROWS = 2;
const byte COLS = 3; 

char hexaKeys[ROWS][COLS] = {
  {'A', 'B', 'C'},
  {'D', 'E', 'F'}
};
byte rowPins[ROWS] = {14, 10}; 
byte colPins[COLS] = {A1, A2, A1}; 


Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
  Serial.begin(9600);
  delay(5000); // runaway protection
  
}

void loop() {
  Keyboard.begin();
  char customKey = customKeypad.getKey();
  if (customKey == 'A') {
    Serial.println("A");
    Keyboard.press(KEY_RIGHT_SHIFT);
    Keyboard.write('l');
    Keyboard.releaseAll();
  }
  else if (customKey == 'B') {
    Serial.println("B");
    Keyboard.press(KEY_RIGHT_SHIFT);
    Keyboard.press(KEY_HOME);
    Keyboard.releaseAll();
  }
  else if (customKey == 'C'){
    Serial.println("c");
  }
  else if (customKey == 'D') {
    Serial.println("d");
  }
   else if (customKey == 'E') {
    Serial.println("E");
    Keyboard.press(KEY_LEFT_ALT);
    Keyboard.write('r');
    Keyboard.releaseAll();
  }
   else if (customKey == 'F') {
    Serial.println("f");
  }
}

Please call out any problems...
Thanks beforehand,
An arduino noob

I suppose the col pins are the pins on the arduino and assume you use a Uno then I do not understand why you assingned twice pin A1 in
byte colPins[COLS] = {A1, A2, A1};
I think it should be
byte colPins[COLS] = {A1, A2, A3};

Oopsie, I looked at my code one more time and it looks like you are right. That's prob why some buttons were linked (wired to different pin but made a mistake during coding). Thanks a lot . That solves one of my problems if you also have solutions for my other problems, that would be amazing.

Thanks

I do not know the keypad and keyboard library but I missed the declaration of the input pins. if not declared as input or input pullup for instance it means the are floating. that means not low or high but somewhere in between.....

see https://docs.arduino.cc/learn/microcontrollers/analog-input
and https://docs.arduino.cc/learn/microcontrollers/digital-pins

BTW: sorry for my bad english, it is not my native

I assume it isn't nessecary because it isn't included on none of the examples given with the library...
It stops working when I set the colums as output and the rows as input_pullup and input, also vice versa, I tried that before making this topic

try

void setup () {
  Serial.begin(9600);
 pinMode(A1, INPUT_PULLUP);                                // zet pinmode
 pinMode(A2, INPUT_PULLUP);                                // zet pinmode
 pinMode(A3, INPUT_PULLUP);                                // zet pinmode
 delay(5000); // runaway protection
}

I'm going to try that tomorrow, as I am not home. I will try it and then let you know my findings! thanks a lot

These three lines can be replaced with:
Keyboard.write('L');
The Keyboard library knows to press the shift key to send a capital letter.

This is the keystroke combination I use in the sim, its Right Shift + l not just a capital L. Its interpetered that way by the simulator.

Remember, there are 2 states possible.
This can be done by the internal resistor (by input_pullup) or adding a pullup resistor (to +5V) , or the other status by a pulldown resistor (resistor to ground) on the input.
A 10K resistor is a good value for a pullup or pulldown resistor.