Keyboard Wars
Volume Number: 4
Issue Number: 1
Column Tag: Pascal Procedures
Keyboard Wars!
By Steven Sheets, Contributing Editor, Hoffman Estates, IL
ADB, Keyboards & TypingBattle
One of the most obvious change to the Mac SE and the Mac // has been the redesign
of the keyboard and mouse interface. There are no longer 2 separate interfaces for the
mouse and the keyboard, each of which could handle only 1 device. Instead the mouse
and keyboards are connected through the new Apple Desktop Bus (or ADB). All of
Apple’s new computers (Mac SE, Mac //, Apple //gs) use ADB. This interface allows
multiple ADB devices to be connected to the computer at the same time. Thus a Mac SE
could have 2 keyboards, a mouse and a third-party ADB device (perhaps a graphics
tablet) all connected to the computer at the same time. While most programs will
recognize a key being pressed no matter what keyboard (an A is always an A), a
program can be written that recognizes the difference between keyboards and acts
accordingly. This article will expand on various ideas involving the ADB, the new
keyboards, and the sample program. The sample program that is provided is
TypingBattle, a multiple keyboard typing contest.
Apple Desktop Bus
The Apple Desktop Bus is a low-speed input-only interface for the new
computers from Apple. The Mac SE and the //gs have a single ADB port while the Mac
// has two ports. Each ADB device (except for the Mouse which must be the last item
on a ADB line) is a pass through device, similar to the SCSI interface. The first ADB
keyboard is plugged into the computer’s ADB port, the next ADB keyboard is plugged
into the previous keyboard (or a second computer port if there is one). Logically up to
16 ADB devices can be connected to a single Computer. In practice, however, the signal
is not powerful enough to go through that many devices. Depending on what style of
keyboard is being used, currently 3-5 keyboards and a mouse is the maximum
configuration.
ADB devices communicate with the computer using the ADB Manager and special
ADB commands. Normally ADB communication is the domain of the ADB device drivers.
The Macintosh Start Manager finds all the ADB devices connected to the computer and
places that info into an ADB device table. It then initializes any ADB device drivers in
the System file. These drivers (stored as ‘ADBS’ resources) will then handle any ADB
communication.
The Mac // and Mac SE System Files contain two standard ADB device drivers, the
mouse driver and the universal keyboard driver. The mouse driver handles all mouse
movements. It also handles all clicking of the mouse button and issues standard
MouseDown and MouseUp events to the Event manager. While two mice can be
connected to the Mac //, the mouse driver was not designed to be able to differentiate
between mice or pass this information over to the application. No information is
passed in the MouseUp or MouseDown event record to explain which Mouse was clicked.
Still, for a bit of amusement, connect to two mice to the Mac // and give them to two
different people. The cursor will move with each move of either mouse, causing much
frustration.
Fig. 1 Two keyboards battle for typing supremacy
The ADB universal keyboard driver handles any keys being pressed or released on
an ADB keyboard. It generates a KeyDown or a KeyUp event for the Event Manager.
However unlike the mouse driver, the keyboard driver passes along information
explaining, not only what key was pressed, but on which keyboard. Prior to the ADB,
the Message field of a KeyDown/KeyUp Event record contained the ASCII Character in
the first byte and the Virtual Key Code in the second byte. With ADB, the Message
field’s first and second bytes are the same, while the third bye contains the ADB
address of the keyboard that was used. This information is the basis of the sample
program, TypingBattle. Two global byte variables are now associated with the ADB
Manager; KbdLast, the ADB address of the last keyboard used and KbdType, the
Keyboard type of the last keyboard used.
While the sample program only uses the Event record for information about the
multiple keyboards, the ADB manager can be accessed directly. The CountADB function
returns the total number of ADB devices connected to the computer. GetIndADB (based
on the device count from 1 to CountADB number) and GetADBInfo (based on the ADB
address of a device) return information about the Device Type, ADB address, service
routine address and data area address. Other ADB Manager calls (ADBReInit, ADBOp
and SetADBInfo) should not be used directly by an application. Any non-keyboard or
non-mouse type of ADB interface would use these commands in it’s own ADB device
driver.
The usage of the ADB has yet to be fully recognized. For a hardware developer,
designing an ADB device has several advantages. For example, the majority of the
current graphics tablets available for the Mac connect to the serial ports, requiring
special software drivers (which do not always work with all software packages) and
the loss of that serial port for other uses. An ADB graphic tablet that emulates an ADB
mouse would work without any special software drivers or loss of port. For the same
reasons, an ADB Piano Keyboard would easily interface into all existing Music
Packages.
Keyboards
There are currently 3 ADB keyboards that can be used on the Mac SE & Mac //.
The standard ADB Keyboard is essentially a duplicate of the older non-ADB MacPlus
keyboard. It has a standard keyboard layout with cursor keys and a Numeric Keypad.
Programs that were written to use the MacPlus cursor keys will function identically
on the standard ADB Keyboard.
Most people do not realize the second ADB keyboard will work on the Mac SE &
Mac //. The Apple //gs uses the ADB interface. It uses the same Mouse as the Mac SE
& Mac //. However the //gs has it’s own ADB keyboard. This keyboard is similar in
layout to the standard ADB keyboard, except slightly smaller. Remember that any ADB
computer can work with any ADB device. While only a large lab would have both the
Macintosh and //gs, it is sometime convenient to know that in a rush, either computer
can use the other keyboard.
The third ADB keyboard is the Extended ADB Keyboard (sometimes still referred
to by it’s development code name “Saratoga”). It has all the features of the standard
ADB Keyboard plus additional keys. These additional keys include 15 Function keys, a
Control Key, and 6 Special purpose keys.
The 15 Function key, called F1 through F15, are across the top of the keyboard.
The first four function keys, F1, F2, F3 and F4, are designed to be assigned the
functions Undo, Cut, Copy and Paste. These functions are printed next to each key on
the keyboard. The Virtual Key Codes (ie. the third Byte of the Longint passed in the
Event field of the event record for keyboard events) of these keys are $7A, $78, $63
and $76. New programs should recognize these Virtual Key Codes, and implement the
functions accordingly. According to Apple’s Guidelines, the F5 thought F15 keys are
intended to be defined by the user, not by the Application. Utilities like QuickKeys by
CE Software or Apple’s promised MacroMaker allow the user to redefine any key to a
specific action. Still, if the developer wishes to do so, a program could use these keys
for it’s own purpose.
The Control key was added for compatibility with applications that communicate
with another operating systems (ie. terminal packages). Pressing the Control key sets
bit 12 of the modifier field of the event record for keyboard events. Since the
Macintosh OS does not use the concept of Control characters, except for a
communication application, this key should not be used by Macintosh applications.
The other 6 Special Keys are intended to give the user greater control of his
application. Each application must handle each special key in it’s own way. The
following are the Keys, their Virtual Key Codes and general guidelines for usage.
The Home key ($73) moves the user to the home position in the application. In a
word processor, this key may move the scroll bar to the top of the document. In a
database, this may move the display to the first field or the first record. The End key
($77) moves the user to the end position in the application. In a word processor, this
key may move the scroll bar to the bottom of the document. The Page Up key ($74)
and Page Down Key ($79) moves the user to the next page (up or down) in the
application. In a word processor, these keys would be equivalent to clicking in the page
up (or down) region of the vertical scroll bar. In a database, these keys may move the
user to the previous or next record. According to Apple Guidelines, the Home, End,
Page Up and Page Down keys should not effect the actual position of the current
insertion point.
The Help key ($72) allows the user to request help from the program. A good
usage of this key would be invoke the About menu (or Help menu, if one exists). The
Forward Delete, or Fwd Del, key ($75) performs similar to the Backspace key. In a
word processor, when the Backspace key is pressed, a character before the current
insertion point is deleted. Using the Forward Delete key in the same situation, a
character after the current insertion point should be deleted. Use this key carefully.
It is a bad idea to allow the user to delete something he can not see (for example, in a
database, delete the next unseen record).
TypingBattle
TypingBattle is a sample program designed to show how to handle more than one
keyboard. It also implements the special keys of the Apple Extended Keyboard. The
game is a simple typing speed contest. First the program prompts each user to type
his name from his keyboard. This tells the application the number of players, the
name of each player and the ADB address of each player’s keyboard. To start a round,
each player must press the return key (so that no one is surprised). Roughly three
seconds later, a random typing Sample is shown. The first player to correctly type it
(including correct punctuation and case), and then press return, wins the round. The
player can backspace over any mistakes, up until the time he presses return. Then,
his line is judged for correctness. The round continues until a winner finishes or
everyone has entered a mistake. The users can use the mouse to select a new round or
start a new configuration. The About Menu or the Help Key will display the About Box.
Last Comments
• The program uses MultiLine, a simple Edit unit. Text Edit was not designed to
have multiple edit fields open at the same time.
• Modifying the Resource source file or ResEdit can be used to add additional typing
Samples.
• Whenever connecting new ADB devices, always power down the computer. A
simple reset is not enough for the system to recognizes when new ADB device
have been connected or detached.
• In the food for thought area, the sample program show how to use multiple
keyboards with a single screen. What about multiple keyboards and multiple
screens? The ADB working together with the Mac // multiple Video cards would
give a true multiuser interface to the Mac. For fun, a MazeWar’s type of game
would be simple to do. On the serious side, a database package that handled
multiple screens/keyboards would have it’s advantages. The hardware would be
much cheaper than setting up multiple Mac’s over Appletalk, while the
performance might even increase (no time spent communicating between
computers). Any takers?
{1}
{ TypingBattle by Steve Sheets 11/15/87 }
{ Simple Demonstration of Multible Keyboards. }
PROGRAM TypingBattle;
USES
MultiLine; {Unit to handle simple editing}
CONST
MaxAllow = 5; {Max Number of Players}
AboutID = 600; {Various Resource IDs}
TextID = 600;
LineID = 601;
AppleMenuID = 1;
FileMenuID = 2;
EditMenuID = 3;
WindowH = 480; {Placement Constants}
VEdge = 40;
CenterTop = 40;
Edge = 10;