Keypad+Switch case help

Hello, people, I've been trying to get a keypad to set the hour on a I2C clock but I'm getting stuck.
I'm using switch case and when I press the "A" on the keypad, it enters on the setting up hour function, it prints the line "Entre com a hora" but it does nothing anymore, please help me.
The code used is this:

#include <Keypad.h>

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] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6, 9}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
}

void loop(){
char key = keypad.getKey();

if (key=='A'){
hora();
}
}

int hora(){
int tempo;
int horaparc;
//lcd.begin(16, 2);
//lcd.print("Entre com a hora");
//lcd.setCursor(0, 1);
char tecla;
int state=1;

switch(state){
case 1:
Serial.println("Entre com a hora");
tecla = keypad.getKey();
if(tecla){
Serial.println("teste");
tempo=tecla;
//lcd.print(hora);
Serial.println(tempo);
tecla = keypad.getKey();
Serial.print(state);
if(tecla=='D'){
state=3;
}else{
state=2;
}
}

break;

case 2:
Serial.print("case 2");
//key=keypad.getKey();
if(tecla){
horaparc=tecla;
tempo=tempo*10+horaparc;
//lcd.print(hora);
Serial.print(tempo);
tecla=keypad.getKey();
if(tecla=='D'){
state=3;
}
}
break;
}
return tempo;
}

You seem to be under the mistaken impression that the getKey() method waits for a key to be pressed. It does NOT. It simply tells you whether a key is being pressed at the time that the function is called.