This is a circuit can be used to support a 4x4 key matrix and be made energy efficient by not requiring perpetual polling. This is done by the use of interrupt inputs.
When a key is pressed, the KBINT ISR (Interrupt Service Routine) is launched with then commences keyboard polling to determine which key was pressed, performs the desired action and then goes back to sleep.
In the sleep state;
The key rows are configured as outputs where all outputs are pulled low.
The key columns are configured as inputs with their pullup resistors enabled.
The KBINT pin is configured as an input with a falling edge interrupt attached and its pullup resistor enabled.
The KBINT is connected in a wired NOR configuration using the diodes sense if any column is pulled low.
The KBINT input is high in the sleep state. When a key is pressed then KBINT pin gets pulled down via the short created between a key column and key row thus activating the ISR.
Note: A reduced part count is accomplishable where there are a sufficent number of edge detect interrupt inputs available for use as the key columns.
In this case each column has an assigned ISR that needs to be configured to process the key input.
If there is a need for ESD (Electrostatic Discharge) protection or current limiting current limiting resistors can be added to the column and row signals (and interrupt inputs) that feed the microcontroller.