Esc.To.Exit
Published By | Date | Version | Knowledge Level | Keywords |
---|---|---|---|---|
Sprezzatura Ltd | 01 MAR 1990 | 1.15+ | EXPERT | ESC.TO.EXIT, DATA |
On the RevTech BBS a few months ago, one of the users asked the question, "how do I check to see if an <esc> key has been pressed without losing what was already in the input buffer ?". In other words, if I am in a lengthy processing loop from which the user ought to be able to escape by pressing <esc>, how do I allow this facility but still allow them to type ahead ?" As this query was never answered I have taken the liberty of using this query as an entry point to the discussion of ESC.TO.EXIT.
Fortunately for the inquisitive developer, RevTech use meaningful names for most of their subroutines (with the possible execption of the Verbs, the RTPs and FAT.FINGER (see later)) so studying the VERBS file provided the answer, a routine called ESC.TO.EXIT. This is a function which, called from a processing loop, returns true if <esc> was pressed and false if it was not. However any keys awaiting processing whilst ESC.TO.EXIT was being called, would be left in the data buffer. To illustrate this try the following section of code.
DECLARE FUNCTION ESC.TO.EXIT EQU TRUE$ TO 1 EQU FALSE$ TO 0 * * Set a time for the loop to repeat * END.LOOP = TIME() + 4 USER.ESCAPED = FALSE$ LOOP * * Insert processing loop here * UNTIL TIME() > END.LOOP OR USER.ESCAPED IF ESC.TO.EXIT() THEN USER.ESCAPED = TRUE$ REPEAT IF USER.ESCAPED THEN CALL MSG("<Esc> key pressed", "", "", "") END ELSE * * Now build a string to show what has been buffered in the data * statement * NEW = "" LOOP INPUT X,-1 WHILE X DO NEW := X REPEAT CALL MSG(NEW : " entered", "", "", "") END
It is apparent from the above description that when using the ESC.TO.EXIT() function, the user is not restricted to the standard keyboard buffer (the data entered being appended to the DATA statement not stored in the keyboard buffer). Thus using this method the user could type ahead up to a maximum of 64K. This is either an advantage or a disadvantage depending upon your trusting your users to know what they are typing after 15 keystrokes !
(Volume 1, Issue 9, Page 9)