char key = keypad.getKey();
if(key)
{
switch(key)
{
If you don't press a key, the keypad library makes the return value from .getKey() == '\0' and the conditional statementif(key)
does not execute.
You can see that with this simple example
void setup() {
Serial.begin(115200);
char key = '\0';
if (key)
Serial.println("key");
else
Serial.println("NoKey");
}
To make the cases repeat with loop() until a new key is pressed try heading your code with this
static char switchKey = '\0';
char key = keypad.getKey();
if(key != '\0')
switchKey = key;
switch(switchKey)
{
case '1':
if you want a case to not repeat add switchKey = '\0';
before the break statement in the case.