help - escape key detection
gm at trsvax
gm at trsvax
Wed Sep 25 08:40:00 AEST 1985
There is this excellent book out from Prentice-Hall titled "Advanced
UNIX Progamming" by Marc J. Rockland. Under the chapter devoted to
signals, there is this section which talks about escape key detection:
---------------------------------------------------------------------------
There's one other common use for ALARM. Ordinarily we would consider
the scheme we are about to present too harebrained to be included in a
sober book like this one, but because it's used in the popular text editor
vi (from Berkeley), we'll describe it anyhow.
The problem this scheme solves is this: Many CRT terminals transmit an
escape sequence when a function key like HOME or END is pressed. Such a
sequence consists of the escape character followed by a series of additional
characters that indicate which key was pressed.
[describes how HOME key works...]
This is the solution adopted by vi: When an escape is read, the alarm
clock is set to one second and then a read is issued for the next character.
If read returns before the alarm goes off, it is assumed that characters
could have been transmitted that quickly only if they were generated by the
keyboard as a function key was pressed; if the alarm goes off (interrupting
read), it is assumed that the characters were typed slowly by a human--that
is, the escape itself was actually pressed.
[goes on to describe problems with this system; eg. fast typist or
a slow system could screw this scheme up.]
---------------------------------------------------------------------------
It gives a section of code which would simulate what vi does.
If you are really interested in this, you should get a copy of this book.
[The text in this note is provided by an individual and is not supported
by Tandy Corp. Because the original recording was made with analog
equipment, the high resolution of the Compact Disk can reveal limitations
of the source.]
George Moore (gm at trsvax.UUCP)
More information about the Comp.unix
mailing list