If you're able to understand arduino C, look at the arduino matrix keyboard example. Nice FSM implementation https://domoticx.com/arduino-library-keypad/