From C64-Wiki
Jump to navigationJump to search

The zeropage address 197 ($C5 in hexadecimal, official name LSTX) holds what was the most recent keyboard code before the last keyboard scan was performed using the SCNKEY routine. If multiple keys are pressed, this address will contain the highest keyboard code.

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.

Examples[edit | edit source]

10 X = PEEK(197): IF X<>39 THEN 10
20 POKE 198,0: K$ = "N"

This example was presented in Loadstar #5, as an alternate "space-optimized" method of checking if a key is pressed. It was compared to using GET, and checking all four character possibliies that could arise from pressing a single key.