39. Input with timeout ~~~~~~~~~~~~~~~~~~ In some applications, especially Educational programs, it is useful to have an input routine which "times-out" if no key is pressed for a certain number of seconds. This is possible for single-character routines like INKEY, but not with INPUT. This Function solves the problem, and also enables you to set limits on the string size. You must pass the minimum and maximum lengths allowed, and also the number of seconds for timeout after the last key was pressed. If the routine times-out before you press , then it will act as if it had pressed for you. If, however, you would rather that it returned the null, (or empty), string instead, then see the REM statement. The example in line 10 allows a minimum of 1 character, and maximum of 12, with a 5-second timeout. You may omit all spaces in the listing, if you wish, except those inside quotes. Thanks to Brian Parker G6JPZ for suggesting the idea, which has been incorporated into the routine given in the Golden Oldie Tip #11. 10 PRINT"Enter name ? ";:A$=FNinp(1,12,5):PRINT A$':GOTO 10 20 : 100 DEFFNinp(min%,max%,secs%):LOCAL G%,G$,GI$:*FX15,1 110 TIME=0:PRINT G$; 120 G$=INKEY$(0):G%=ASC(G$) 130 IF TIME>secs%*100 THEN PRINT:VDU7:=GI$ ELSE IF G%=-1 THEN 120 140 REM Alter the =GI$ in line 130 to ="" if string is to be null on timeout 150 IF (LEN(GI$)=max% AND G%<>13 AND G%<>127) OR (((LEN(GI$)=0 AND (G%<33 OR G%>126)) OR (LEN(GI$)0 OR G%<>13)) THEN VDU7:GOTO 120 160 IF G%>31 AND G%<127 THEN GI$=GI$+G$:GOTO 110 ELSE IF G%=127 THEN GI$=LEFT$(GI$,LEN(GI$)-1):GOTO 110 ELSE IF G%<>13 THEN VDU7: GOTO 120 ELSE PRINT:=GI$