James L. Bruun
For most programs, the normal method of using the INPUT statement to get keyboard characters into a program is perfectly satisfactory. There are times, however, when we need to get a keystroke without stopping the program to wait for a key to be struck.
The ATARI computer has all the features needed to enable the programmer to check the keyboard without waiting for an INPUT statement to get the character. Memory location 764 retains a key code for the last key pressed. Further, when the RUN command is executed, that cell is set to 255 to indicate that no key has been pressed. During the running of a program, that location can be POKEd with a 255 to indicate that we've checked it since the last key was pressed.
Cell 764 is POKEd with 255 only if it isn't already finding it 255, then having a key pressed while the POKE 764,255 instruction is being interpreted. This would cause the keystroke to be lost. In a long program the keystroke isn't often lost, but in a short program it happens quite often.
The following program illustrates the use of these features in a subroutine. First, initialize an I/O buffer and string variable.
Then build the subroutine. Always precede your block of subroutines with an END statement to prevent accidental execution.
Most programs that would need this feature would perhaps be doing complex things if the keystroke has not occurred, but in this one we have chosen to "do nothing" until a key is pressed.
Listing. Read keyboard on the fly.
Download (Saved BASIC)
Download / View (Listed BASIC)
Return to Table of Contents | Previous Section | Next Section