I tried to emulate your case in my own setup using MEGA and 4x4 keypad under Keypad.h Library. I can concurrently enter codes from the keypad and also can observe time out event. The 1-sec time-tick interrupt has been generated using register level instructions as I have no access to Timer1 Library. The codes may be helpful for you.
#include <Keypad.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
const byte ROWS = 4; //four rows
const byte COLS = 4;//3; //three columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'a'},
{'4', '5', '6', 'b'},
{'7', '8', '9', 'c'},
{'*', '0', '#', 'd'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};//connect to the row pin outs of the keypad
byte colPins[COLS] = {5, 4, 3, 2};//connect to the column pin outs of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
volatile int timer_s = 10; // start countdown with 10 seconds
int main_switch = 13; // button to enter code
int main_switch_state = 0; // state on the button
int curSorTracker=0;
void setup()
{
Serial.begin(9600);
lcd.begin(20, 4);
lcd.setCursor(0, 0);
pinMode(main_switch, INPUT_PULLUP);
TCCR1A = 0x00;
TCCR1B = 0x00;
TCNT1 = 0xC2F7; //pre-set value for 1-sec time delay
bitSet(TIMSK1, 0); //local interrupt enable bit
sei(); //global interrupt enable bit
TCCR1B = 0x05; //TC1 is running at clkTC1 = clkSYS/1024 = 15625 Hz
}
void loop()
{
main_switch_state = digitalRead(main_switch);
if (main_switch_state == 0)
{
char ch = keypad.getKey();
if(ch !=0)
{
lcd.write(ch);
curSorTracker++;
}
}
}
ISR(TIMER1_OVF_vect)
{
TCNT1 = 0xC2F7;
timer_s -= 1; // decrease countdown by 1 second every time
if (timer_s <= 0)
{
Time_out();
}
}
void Time_out()
{
lcd.setCursor(0, 1);
lcd.print("Time Out!");
while(1);
// Print on lcd the time is over and spin in an infinite loop
}