I'm using the Keypad.h library Arduino Playground - Keypad Library to make a custom keyboard. I've already used this to make a macropad and for that purpose I didn't need multiple keypresses, but for my new project I'll need more than one key at a time. I've seen references online and even on the project home (the link above) that mention multi-press support. What I haven't seen is a working example of this to duplicate and make my own.
To start off with, I'm using Cherry MX clones for the keys and using diodes on each key to prevent ghosting. I'm also using a SparkFun ProMicro clone board. This is all working great on my macropad and my 2x2 test matrix I'm using as a proof of concept, but only for one keypress at a time.
The code I'm using for the test project is below. I've added some debug logging to the event handler to see what is going on and the logged statements show expected behaviour correctly for the first key.
#include <Keyboard.h>
#include <Keypad.h>
const byte ROWS = 2;
const byte COLS = 2;
char hexaKeys[ROWS][COLS] = {
{1, 2},
{3, 4}
};
byte colPins[COLS] = {4, 5};
byte rowPins[ROWS] = {6, 7};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup(){
Serial.begin(115200);
Keyboard.begin();
customKeypad.addEventListener(keypadEvent);
customKeypad.setHoldTime(10);
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
Serial.println(customKey);
switch(customKey) {
case 1:
Keyboard.press('1');
Keyboard.press(KEY_RETURN);
break;
case 2:
Keyboard.press('2');
Keyboard.press(KEY_RETURN);
break;
case 3:
Keyboard.press('3');
Keyboard.press(KEY_RETURN);
break;
case 4:
Keyboard.press('4');
Keyboard.press(KEY_RETURN);
break;
}
}
}
void keypadEvent(KeypadEvent key){
switch (customKeypad.getState()){
case PRESSED:
Serial.println("Pressed");
break;
case RELEASED:
Serial.println("Released");
Keyboard.releaseAll();
break;
case HOLD:
Serial.println("Hold");
break;
}
}
Does anyone know what else needs done to the above code or hardware to support multi-keypresses?