The diagram below is a 16 key keyboard. From what I understand, the microcontroller is constantly clocking all the rows to logical lows at a high frequency one after another sequentially. Each line of the output port (D0, D1, D2, D3) will go from a +5 volts to ground hundreds or thousands of times/second. Say you press the "D" key. When the row (D0 of the output port) goes low, this will also put a ground or low on D2 of the input port. The microcontroller now knows that row D0 is low and also column D2 is low. This tells the microcontroller to fetch the hexadecimal code for the D key. This is going to be 8 bits of information--highs and lows. This is also called the "Scan Code" and it is output on pin 3 of a PS/2 connector to the computer.
(http://i1132.photobucket.com/albums/m565/Endzone2/keyboard1.jpg)
But it isn't just 8 bits of information. There is a start bit on the next negative going clock pulse, then the 8 bits of data, then a parity check bit, and then a stop bit. So each letter transmits 11 bits of serial date out of pin 3 on the PS2 connector to the computer.
(http://i1132.photobucket.com/albums/m565/Endzone2/keyboard3.jpg)
Here is the technical explanation from the author.
(http://i1132.photobucket.com/albums/m565/Endzone2/keyboard2.jpg)
If I have anything obviously wrong please correct me. Next step is to see what the computer does with the scan code.
Here are 2 good links where I got this info.
http://nptel.iitm.ac.in/courses/Webcourse-contents/IISc-BANG/Microprocessors%20and%20Microcontrollers/pdf/Teacher_Slides/mod3/M3L7.pdf
http://retired.beyondlogic.org/keyboard/keybrd.htm