Commodore 64 Dynamic Keyboarding – A Clever BASIC Trick
Introduction
One of the pleasures of browsing old Commodore computer magazines is discovering clever programming tricks. While reading the January–February 1992 issue of the Danish computer club magazine Klubnyt for Commodore 64/128, I came across a short BASIC routine that loads and runs another program. What caught my attention was how it worked. The Commodore 64 could effectively press its own RETURN key.
This technique is known as dynamic keyboarding. It allows a program to imitate keystrokes without anyone touching the keyboard. It was already being taught in computer magazines during the 1980s, and you can still try it today without knowing machine language.
Teach Your Commodore 64 to Press RETURN
Switch on your Commodore 64 or start your favourite C64 emulator. Save any work you already have in memory, then type NEW to start with an empty program. Enter these five lines of BASIC and type RUN.
10 PRINT CHR$(147)
20 PRINT "PRINT 6*7"
30 POKE 631,19:POKE 632,13
40 POKE 198,2
50 END
Look for the answer 42 on the screen. Notice that line 20 contains the calculation inside quotation marks. Normally, BASIC would simply display the words and numbers inside those marks. Here, the computer should also execute the command it has just displayed.
Try changing the calculation in line 20 to PRINT 9*9 (keeping the quotation marks around it). Run the program again and look for 81. The novelty is not what the command does, but how it gets executed.
What Just Happened?
The Commodore 64 has a wonderfully flexible screen editor. Move the cursor onto an earlier BASIC command displayed on the screen and press RETURN. The computer can execute that command again without you having to retype it.
Our program takes advantage of this feature. Line 10 clears the screen and line 20 displays a BASIC command. Lines 30 and 40 prepare two keystrokes using the keyboard buffer, a small area of memory that holds characters waiting to be processed.
The BASIC command POKE writes a value directly into a memory location. Here is what each POKE does:
| Instruction | Purpose |
|---|---|
POKE 631,19 |
Places a HOME character in the keyboard buffer. |
POKE 632,13 |
Places a RETURN character next in the buffer. |
POKE 198,2 |
Tells the computer that two characters are waiting. |
After the program ends, BASIC displays its READY prompt. The waiting HOME character moves the cursor to the top-left corner of the screen. RETURN then submits the command on that line. BASIC executes it in direct mode, just as if you had typed a command at the READY prompt.
The clever part is that we do not need to fit the entire BASIC command into the keyboard buffer. The screen already holds the command. We only need to supply the keystrokes that execute it.
Make Something Useful: An Automatic Program Loader
Imagine having several BASIC programs on a floppy disk and wanting one program to launch another. Dynamic keyboarding can help us do exactly that.
You will need a writable floppy disk in drive 8, or a writable disk image (such as a D64 file) attached to drive 8 in your emulator. Use a spare disk or disk image for this experiment.
Type NEW and enter this demonstration program:
10 PRINT CHR$(147)
20 PRINT "WELCOME TO PROGRAM TWO!"
30 PRINT "THE AUTOMATIC LOADER WORKED!"
Save it to the disk using the following command. Wait for BASIC to display READY before continuing.
SAVE "SECOND",8
Now type NEW and enter the automatic loader below. This example follows the screen-spacing approach described by Jim Butterfield in his May 1986 COMPUTE! article on loading and linking Commodore programs.
10 PRINT CHR$(147)
20 PRINT:PRINT
30 PRINT "LOAD"+CHR$(34)+"SECOND"+CHR$(34)+",8"
40 PRINT:PRINT:PRINT:PRINT
50 PRINT "RUN"
60 PRINT CHR$(19)
70 POKE 631,13:POKE 632,13
80 POKE 198,2:END
Save the loader with SAVE "LOADER",8 before running it. Loading the second program replaces the loader in BASIC memory, so saving it makes it easy to try again.
Type RUN and watch the screen. The loader displays the LOAD and RUN commands, leaving blank lines for the messages that appear during disk loading. Line 60 moves the cursor home, and the final two lines prepare two RETURN keystrokes. The first submits LOAD; the second is intended to submit RUN once loading is complete.
If the experiment succeeds, the screen will clear and display the welcome message from the second program. If you see a disk error, check that drive 8 contains the disk with SECOND saved on it. You can reload your loader with LOAD "LOADER",8 and try again.
Why Not Just Use LOAD?
Commodore BASIC V2 allows a running program to load another BASIC program. However, loading this way can keep variables from the earlier program and cause problems when the programs differ in size.
Dynamic keyboarding offers another approach. By submitting LOAD and RUN as direct commands, we allow the second BASIC program to start afresh. This is particularly useful when building a menu that launches separate programs.
Something to Experiment With
Why not create three small BASIC programs on a disk and build a menu to launch them? One could be a calculator, another a favourite game, and the third a colourful graphics demonstration. Start by changing the filename SECOND in the loader to match another BASIC program on your disk.
You can also explore other commands using the first experiment. The Commodore character system, known as PETSCII, uses code 19 for HOME and code 13 for RETURN. The keyboard buffer normally holds up to ten characters at memory locations 631 to 640. Location 198 records how many are waiting.
What other combinations of commands and simulated keystrokes could you devise? Remember to save your work before experimenting with commands that change or replace a program.
Conclusion
Dynamic keyboarding reveals something remarkable about the Commodore 64. With a handful of BASIC statements, a program can operate the same screen editor that we use ourselves.
Some of the most ingenious ideas in home computing did not require new hardware or programming languages. They simply required someone to look at an existing feature in a different way.
Go on, switch on your Commodore 64 and give it a try.
Writer's Notes
Reader Guide
The following material expands on the terminology, historical context, technical concepts, and related reading connected to this article.
Glossary
Some of the terms used in this article have specialised, historical or technical meanings. This glossary provides additional context for selected terms and ideas.
- Dynamic keyboarding
- A programming technique that makes a computer act as if keys had been pressed by placing character codes in its keyboard buffer. On the Commodore 64, it can execute BASIC commands already printed on the screen, without requiring machine language.
- Screen editor
- The Commodore 64 interface that allows a user to move the cursor to a displayed line and press RETURN to submit it. Dynamic keyboarding exploits this behaviour to execute commands printed by a program.
- Keyboard buffer
- A small area of memory that holds keystrokes waiting to be processed. On the Commodore 64 it occupies locations 631–640, while location 198 records how many characters are waiting.
- POKE
- A BASIC command that writes a value directly to a specified memory location. Here it places simulated keystrokes in the keyboard buffer and sets the count that tells the computer to process them.
- Direct mode
- The mode in which Commodore BASIC executes a command entered at its prompt immediately, rather than as a line within a running program. Dynamic keyboarding uses it to issue commands such as LOAD and RUN after the first program ends.
Frequently asked questions
Curious about something you’ve just read? These frequently asked questions explore some of the key ideas, details and questions surrounding the topic.
What is dynamic keyboarding on the Commodore 64?
Dynamic keyboarding is a technique that uses simulated keystrokes to make the Commodore 64 execute commands displayed on its screen. It relies on the screen editor and keyboard buffer, so it does not require machine-language programming.
How does a program make the C64 press HOME and RETURN?
The program places the PETSCII codes 19 and 13 in the keyboard buffer at locations 631 and 632, then sets location 198 to 2. When the program ends, HOME moves the cursor to the top-left corner and RETURN executes the command on that screen line.
Can dynamic keyboarding load and run another program?
Yes. A loader can display LOAD and RUN commands, then place HOME and two RETURN characters in the keyboard buffer. After the loader ends, the computer processes those keystrokes to load and run the second program.
Why use dynamic keyboarding instead of LOAD inside a program?
Loading another BASIC program from within a running program can have surprising effects on execution and retained variables. Dynamic keyboarding instead executes commands in direct mode, as if someone had entered them at the keyboard.
References
Dynamic keyboarding was already documented in the original Commodore 64 Programmer's Reference Guide. The technique was subsequently explored in articles published by COMPUTE! during the 1980s and continued to circulate through enthusiast publications, including the Danish computer club magazine that inspired this article in 1992.
For readers wishing to explore the technique further, the following references provide considerably more technical detail.
- Commodore 64 Programmer's Reference Guide: The Screen Editor.
- Dynamic Keyboard for Commodore Machines, Part 1, COMPUTE!, October 1985.
- Loading and Linking Commodore Programs, Part 3, COMPUTE!, May 1986.
- Klubnyt for Commodore 64/128, Volume 3, Issue 1, January-February 1992, page 14.
- Dissecting a C64 Autoboot Program, Bumbershoot Software, January 2026.
Disclosure
This article is an independent exploration of Commodore 64 programming techniques inspired by historical computing publications. Artificial intelligence assisted with interpreting the original Danish source, developing the BASIC examples and creating the banner illustration. The example programs are provided for educational and experimental purposes.