Latching funktions keypad

Hi.

I am currently trying to make the arduino control a lot of things on my boat. the first thing i wanted to do was
turning things on and off via a 4x4 keypad. Press A once for turning relay 1 on, then turn it off by pressing A again.

How can i do that?

The code so far, i would like not to use a second button for turning off.

#include <Keypad.h>
int relay1Pin = 11; // relay
int relay2Pin = 12;

const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {40, 41, 42, 43}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {44, 45, 46, 47}; //connect to the column pinouts of the kpd

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

void setup(){
Serial.begin(9600);
pinMode(relay1Pin, OUTPUT); // relay
pinMode(relay2Pin, OUTPUT);
}

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

if (customKey){
Serial.println(customKey);
}

if (customKey == 'A') // relay 1 on
{
digitalWrite(relay1Pin,HIGH);
}
if (customKey == 'B') // relay 1 on
{
digitalWrite(relay1Pin,LOW);
}
}

You need a state variable for each relay. Then, when the relevant key is pressed you can check the state variable associated with the key's relay so you know whether to turn it on or off. Change the state variable at the same time ready for the next time the key is pressed.