Timex Tips: ESC or Control Keys?

Author(s): Chuck Dawson
Publication: ZX-Appeal
Pub Details: ZX-Appeal Summer 87
Date: Summer 1987
Pages: 33

QUESTION: How do you go about specifying certain keys that we do not have on the Sinclairs? There is no ESCAPE or CONTROL keys on the keyboard, but it is used in Mterm. How can we use it in BASIC programs?

ANSWER: People tend to be intimidated by keyboards, especially if there seem to be many more keys than on a standard typewriter. The truth is, since we are limited to eight binary digits, there are only 256 possible combinations of ones and zeros. The T/S keyboard has only 40 keys, and yet it can send every one of these 256 combinations. Some, of course, are accessed by first getting the ‘F’ or ‘E’ or ‘G’ cursors. If you look in the manual at the table of characters, you will see that only a few codes near the beginning are ‘not used’. These are usually used to give commands to a printer. For example, most printers use a ’12’ to advance the paper to the top of the next sheet. Many use ’15’ to set the condensed type. Most use the ESCAPE code (27) plus another number to do a variety of other things. In BASIC, this would take the form LPRINT CHR$ 27 or LPRINT CHR$ 15. The Mterm terminal emulation program produces an ESCAPE by holding down SYMBOL SHIFT and pressing ENTER. Another computer may have an ESCAPE key to produce the same results. By the ASCII convention, printable characters do not begin until 32, so those early codes that are used to control printers are called ‘Control Codes’. Some computers have a CONTROL key which gives access to those codes by holding down the CONTROL key and pressing another key. A ‘1’ is Control A, a ‘2’ is Control B, and so forth. In BASIC, these would be represented by CHR$ 1, CHR$ 2, and so forth. The T/S uses many of the codes above 127 for its KEYWORDS. For example CHR$ 180 is the TAN function on the 2068 and an inverse ‘0’ on the 1000. That is why, when machine code is poked into a REM statement, you sometimes see letters, keywords, graphic characters, and so on. The computer is faithfully displaying each code as it has been programed to do. So there you have it. Just think of each keystroke as sending a number from 0 to 255 to the computer (or to the Modem or to the Printer) and suddenly things don’t seem quite as complicated as they at first appeared.

Reprinted from the DATA EXPANSION, the N/L of the Ft.Worth T/S Users Group