Keyboard using keypad and keyboard libraries together

I am trying to make a keyboard script for an stm32 based development board using the keypad and keyboard libraries. I used a default script from the keypad library then added a keyboard function from the keyboard library to send keystrokes to the connected computer. My problem is that the script below does not send any keystrokes. I am able to send a key when I have a keyboard.write function alone, but not when it is inside that if statement. I can also send the pressed letter through serial (using an UNO, not the stm32 board as It doesn't connect to the serial monitor) so I know that the keypad script works alone.
#include <Keyboard.h>
#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;

char hexaKeys[ROWS][COLS] = {
{'A', 'B', 'C'},
{'D', 'E', 'F'},
{'G', 'H', 'I'},
{'J', 'K', 'L'}
};

byte rowPins[ROWS] = {PA2, PA3, PA6, PB1};
byte colPins[COLS] = {PB11, PB14, A9};

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

void setup(){
Serial.begin(9600);
Keyboard.begin();
}

void loop(){
char customKey = customKeypad.getKey();

if (customKey){
//Serial.println(customKey);
Keyboard.write(customKey);
}
}
#include <Keyboard.h>
#include <Keypad.h>

const byte ROWS = 4;
const byte COLS = 3;

char hexaKeys[ROWS][COLS] = {
{'A', 'B', 'C'},
{'D', 'E', 'F'},
{'G', 'H', 'I'},
{'J', 'K', 'L'}
};

byte rowPins[ROWS] = {PA2, PA3, PA6, PB1};
byte colPins[COLS] = {PB11, PB14, A9};

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

void setup(){
Serial.begin(9600);
Keyboard.begin();
}

void loop(){
char customKey = customKeypad.getKey();

if (customKey){
//Serial.println(customKey);
Keyboard.write(customKey);
}
}
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?