From C64-Wiki
Jump to: navigation, search

The zeropage address 197 ($C5 in hexadecimal) holds what was the most recent keyboard code before the last keyboard scan was performed using the SCNKEY routine. The most recent keyboard code is available at address 203.

Each time SCNKEY scans the keyboard, it places the resulting keyboard code in address 203, but before doing this, the previous keyboard code already present in 203, is saved to address 197. This is part of the mechanism that detects the "moment" where a key is pressed down, ensuring that the resulting character is only printed once on the screen, rather than several times for as long as the key is being pressed.

The SHIFT, CTRL and Commodore logo keys uses a similar scheme, involving addresses 653/$028D for the most recent state of these keys, and address 654/$028E for the previous state.