Classic Computer Magazine Archive CREATIVE COMPUTING VOL. 9, NO. 1 / JANUARY 1983 / PAGE 302

Apple cart. (reading Apple II keyboard) (column) Michael Coffey.

Apple Cart

Earlier this year, we received many letters because a game program we published contained a bug. The problem involved an incorrect method of reading the Apple II keyboard. Most of the letters contained incorrect fixes for the bug. Maybe we should take a look at the problem.

We want to write a program that does not hang around waiting for keyboard input but that uses keyboard input whenever it becomes available. The Apple can tell us whether or not a key has been pressed recently if we cooperate.

One memory locationis set aside to hold the last key pressed. Another is reserved for the program to tell the hardware that the last key has been read. The first location is also used by the hardware to tell the programmer that there is a new key to read.

Our strategy is to read that first location frequently to see if a new key has been pressed. When a new key is ready, we must do two things: save the key value in another location and tell the hardware that we have read the key.

In Basic, we use the PEEK function to learn whether a key is available. If the value of PEEK(-16384) is greater than 127, a key has been pressed. We will use the variable KD, short for key data, to denote this address.

When a key is ready, the function PEEK(-16384) yields the ASCII code for the key. The CHR$ function turns an ASCII code into a single-character string. We will assign the character string to the variable K$.

Once we have determined K$, we must clear the keyboard so that more keystrokes can be recorded. We POKE a value into location -16368--any value. We use KC to stand for the address used for keyboard clearance.

Listing 1 is a program that reads the keyboard and maintains a special cursor on the screen. The program will keep the latest character in K$, call subroutine 2000 whenever a key is pressed, and call subroutine 3000 on each loop where no key is pressed.

Subroutine 2000 simply displays the new value of K$. Subroutine 3000 displays an underline cursor and backs up one space. If you remove the backspace function (CHR$ (8)), you will get an idea of how many times the loop runs between keypresses.

The program works for all literal keys, but some control keys can make the screen look strange. The main loop is a good starting point for any keyboardprocessing program. The subroutines should be adapted for your specific purposes.

Incidentally, the technique of repeatedly checking a keyboard or other input device is called polling. You now know how to do polled keyboard input. Congratulations.

Repeaterrr

Speaking of keys, we recently received a small board that converts an Apple keyboard into one with automatic repeat on all the keys except Rest. The Repeaterrr, though hard to spell, is easy to use.

When you hold down a key, it will repeat itself to the Apple. You can adjust the length of time the key waits before repeating. If you make the period very short, you will end up with keybounce. If you make it very long, guest typists will never notice your modification. We like to make it just long enough to avoid accidental repeats.

Besides the autorepeat feature, you get a fast repeat feature. Just press the repeat key and the key will repeat itself much faster than usual. Your software will hardly be able to keep up with the keyboard in fast repeat mode.

The board must be sandwiched between the keyboard and the keyboard encoder board. Consequently the bottom of the computer must be unscrewed and removed. Apples with old style keyboards can not use this modification.

The Repeaterrr comes with very explicit instructions and is a good buy at $24.95.

Numeric Keypad

This hardware add-on is dedicated to VisiCalc users everywhere. Anyone else who types many numbers can key along. Numbers and related symbols can be produced with the keypad from The Keyboard Company.

The keypad is easy to install if you don't mind pulling the computer apart. First, you must remove the bottom plate of the Apple, carefully unplugging the standard keyboard. Next, plug the new keypad into the motherboard and plug the standard keyboard connector into a new circuit board that comes with the numeric keypad. Replace the bottom plate and you are ready to compute again.

The 5" cable should be threaded through one of the slots in the back of the Apple. A molded fitting on the cable prevents it from being yanked out of the computer by accident. The unit measures 8.25 X 5 X 1.5 and weighs only a few ounces.

The Numeric Keypad provides a slightly more distinct feedback than the standard keyboard, has bumps on two of the keys to aid in positioning your fingers, and is otherwise similar to the Apple keyboard.

The 24 keys are arranged in three groups. The central group includes the digits 0-9, the decimal point, and a 00 key. To the left of the digits is a group of VisiCalc editing keys including ESC, both arrows, and a space bar equivalent.

To the right of the digits The Keyboard Company has mounted a return key, both parentheses, and the numeric operations -, /, +, and *. The last key on the lower right is labeled PRINT and produces a question mark when pressed. See Figure 1 for a more precise layout of the keys.

As far as we can tell, the keypad interferes in no way with the operation of any Apple II software. The advantages are obvious and well worth the price to anyone who spends more than a few hours a week typing numbers.

Magic Keyboard

One of the wildest keyboard modifications we have seen comes from Southern California Research Group. Magic Keyboard enables you to rearrange the keys on your keyboard. If you want to study keyboard layout technology and psychology, this one is for you.

This 2.5 X 3 board must be planted in the keyboard socket on the Apple motherboard. The cable from the keyboard can then be plugged into the Magic board. This means that you have to remove the bottom plate from your Apple again.

Before putting things back together, you must make a few choices. You can choose an alternate alphabetic layout and a numeric layout. The instructions detail the available options. Dvorak standard, left hand only, right hand only, and other layouts are all built in.

After installing, you will be able to shift between regular QWERTY layout and the preselected alternate layout with the flick of a switch. The press of a button will shift you between the alphabetic and numeric layouts. The switch and the button are both mounted on a little pad that can be stuck to the Apple or any other convenient surface.

We tried the Dvorak layout and found that we did not have enough time to learn it. As workers that are forced to use many different keyboards, we can't see any payoff for us in learning a new one at the moment. I encourage layout experimentation and hope for the day when all keyboards are programmable.

Table: Listing 1.

Photo: Numeric Keypad.

Photo: Repeaterrr.