I have solved my problem using attachInterrupt() function.The loop() runs liftStops() continuously and if there is a keyPress, it is recorded by the interrupt.
void setup(){
attachInterrupt(digitalPinToInterrupt(3), floor1, CHANGE);
}
loop(){
liftStops();
}
void liftStops(){
if(qlift1[f1+1] != NULL){
while(timer<100){
distance = (speed*timer);
motorClockwise();
Serial.println(distance);
if(qlift1[f1+1] == '1' && distance == 0){
motorStop();
deQueue();
delay(5000);
return;
}else if(qlift1[f1+1] == '2' && distance == 30){
motorStop();
deQueue();
delay(5000);
return;
}else if(qlift1[f1+1] == '3' && distance == 60){
motorStop();
deQueue();
delay(5000);
return;
}else if(qlift1[f1+1] == '4' && distance == 90){
motorStop();
deQueue();
delay(5000);
return;
}else if(qlift1[f1+1] == '5' && distance == 120){
motorStop();
deQueue();
delay(5000);
return;
}else if(qlift1[f1+1] == '6' && distance == 150){
motorStop();
deQueue();
delay(5000);
return;
}
timer = timer+0.167;
delay(200);
}
}
}
If any key is pressed during delay(5000) even that gets recorded.