Home Alarm with a 3 wire 4x3 analog keypad nearly done but need some help please

Hi liudr. Thank you for the revised code. This does work but when the alarm is tripped any keypad press turns the alarm off. I tried it this morning. I am reading all I can find about state machines too.
Perhaps I should leave it today as I have had more injections into my spine and they hurt badly. I may have a look later if I feel better. I hope I am not taking up too much of your time on this.
Regards
Jeremy