To help you understand the progrogramme:
Think of the key pad as a grid, The columns are connected to outputs and the rows to inputs.
If you set an output on then look at each input you will see of a switch is pressed because an input will go high.
You know which switch because you know whic output you put on.
If no switch is pressed you put the next output - collumn on and repeat the process until the whole keypad has been scanned.