How exactly do Diodes give a keyboard the magical powers of NKRO?
The real question is how on Earth a keyboard without diodes even manages to work.
Basically, a typical (non-capacitative) keyboard is a switch matrix. You have a bunch of typewriter keys which are momentary contact normally open single-pole single-throw switches. Like a doorbell.
And the way they're wired is this: there are wires going by rows and columns, one of the two connectors on each switch is wired to a row, and the other one is wired to a column.
The keyboard controller is connected to the columns, and can tell if a column is connected to electrical power. It is also connected to the rows, and applies electrical power to each one in turn.
So if the switch in row 5 and column 3 is pushed down to close it, when a voltage is applied to row 5, it will come out on column 3.
Assume for the sake of illustration that the controller either connects +5 volts, or a high-impedance state, to the rows.
The columns are then connected to ground through a resistance in the controller, and if current flows through that resistance, this means a voltage has been detected.
What happens when more than one button is pushed at the same time?
If no two buttons that are pushed are in the same column, there is no problem. When voltages are applied to each row in turn, each column will only show a voltage if it is connected to that row by a button that was pushed, so the keyboard controller will properly detect which buttons are pushed in every row.
But if two buttons are pushed in the same column, then when a voltage is applied to the row in which one of those buttons is located, it travels through the two closed switches, first from row to column, and then from column to row, so that the matrix acts as if the keyboard controller applied the voltage to
both of the rows in which these two buttons were located.
Note that you have a positive voltage from the keyboard controller, flowing into the row wire, through the first button from its row contact to its column contact, and then incorrectly energizing a second row wire by flowing from the column contact to the row contact of the second button.
So if we added a diode to every one of the buttons, so that when the switch was closed, it was only possible for current to flow from the row wire to the column wire, and
not back from a column wire to a row wire, it wouldn't be possible for two buttons in the same column to make buttons in a row not currently being scanned still be detected.