This simple keyboard scanner scans each key until it finds one pressed. It then loads the scan code into the pkey register where the host finds it when it does a programmed I/O read.
The host will know to do a read when it gets an interrupt. The interrupt occurs when a key is pressed and is cleared when the host does a read hren.
In practice, one would not scan at the speed of the processor clock. One would scan more slowly to stop the wires in the keyboard transmitting RF interference. Also, one should use extra register on asynchronous input pressed (see crossing clock domains) to avoid metastability. Or, typically, one might use a separate microcontroller to scan a keyboard.
Note, a standard PC keyboard generates an output byte on press and release and implements a short FIFO internally.