Sinclair ZX Spectrum Service Manual 
Spectrum For Everyone  https://spectrumforeveryone.com/ 
14 
1.8 KEYBOARD SCANNING 
Every 20ms (i.e. once per maskable interrupt), the CPU systematically scans the keyboard recording which 
keys (if any) have been pressed. The scanning method is described below with the aid of the diagram 
below. As the diagram clearly illustrates the keyboard consists of an 8 x 5 matrix, the inter-section of each 
row and column bridged by a normally open switch contact. The row `outputs` and column `inputs` are 
shown connected by separate ribbon cables KB1 and KB2, one to the ULA and the other to the high order 
address lines A15-A8. Pull-up resistors R64 through R68 ensure that when the address bus is in the high Z 
state, or none of the key-switches is closed, row outputs KB0 to KB4 remain high. 
 
 
When the keyboard scanning routines are entered the CPU performs successive I/O read cycles setting 
the IOREQ and RD lines to the ULA, low. At the same time, the I/O port addresses placed on the upper 
half of the address bus are modified with each cycle such that each of the address lines A15 through A8 is 
set low in turn, the other lines remain high. 
The sequence starts with I/O port address FE driving address line A8 low. The keyboard matrix also sees 
this potential on column 6 applied via D6 and the ribbon cable KB2. Thus, when any of the switches on 
the inter-section with column 6 is pressed, the corresponding row output supplying the ULA vis the second 
ribbon cable (KB1), is pulled low. The row signal(s) is subsequently inverted by the ULA and placed on one 
of the five low order data bus lines. For example, if the CAPS SHIFT key is pressed row one output drives 
data bus D0 high and so on. The sequence ends with I/O address 7F when column 8 is addressed. In this 
instance, operation of the SPACE key drives D0 high. Clearly, the keyboard scanning routines make the 
distinction between the CAPS SHIFT and SPACE key by knowing which address line is being driven.