This is an interesting routine.
This is what I put together, using the !GET.KEY
function to obtain each key in it's entirety.
subroutine GET_INPUT( the.TIMEOUT, the.LENGTH, the.INPUT, the.STATUS)
* Use !GET.KEY in a loop to get input, with a timeout
*
* The value of the.INPUT is not displayed, and is removed
* This routine focuses on capturing NEW input and is NOT an editor
* for existing details.
* the.STATUS : 0 = All good - user entered a value
* 1 = Badness happened - no input
* 2 = Input timeout
$include UNIVERSE.INCLUDE ATFUNCTIONS.H
$include UNIVERSE.INCLUDE TERMINFO
nap_TIME = 10 ;* Milliseconds
the.INPUT = ''
the.STATUS = 0
* When do we abandon this input attempt?
end_TIME = system(99) + the.TIMEOUT
loop
* Check if there is anything in the input buffer
input keys_waiting, -1
if not(keys_waiting) then
* No key pressed, get busy waiting
loop
nap nap_TIME
input keys_waiting, -1
if keys_waiting then
* We have something to do, stop waiting
exit
end else
* Check if we have timed out
if system(99) > end_TIME then
* Exit our wait loop
the.STATUS = 2
exit
end
end
repeat
* If we have timed out exit our input loop
if the.STATUS = 2 then exit
end
* get the key waiting on the input buffer
code.KEY = ''
in.KEY = ''
call !GET.KEY( in.KEY, code.KEY)
begin case
case code.KEY = 0
* Normal keys
if in.KEY > char(31) and in.KEY < char(127) then
if len(the.INPUT) < the.LENGTH then
the.INPUT = the.INPUT : in.KEY
crt in.KEY:
end else crt BELL:
end else crt BELL:
case in.KEY = KEY.BACKSPACE
* Remove a character
if len(the.INPUT) then
the.INPUT = the.INPUT[1,len(the.INPUT)-1]
* Backspace 1 char, delete 1 char
crt @(IT$CUB): @(IT$DCH):
end else crt BELL:
case in.KEY = char(10) or in.KEY = char(13)
* user has <ENTER>ed their value!
exit
case 1
* nope - these are not valid
crt BELL:
end case
* Check if we have timed out
* Cannot have a busy keyboard stop the timing checks
if system(99) >= end_TIME then
* Times up - Exit our input loop
the.STATUS = 2
exit
end
repeat
if the.STATUS = 2 then the.INPUT = ''
return
------------------------------
Gregor Scott
Software Architect
Pentana Solutions Pty Ltd
Mount Waverley VIC AU
------------------------------
Original Message:
Sent: 05-10-2023 17:10
From: Brian Speirs
Subject: Is it possible to set an input timeout for !EDIT.INPUT
You could also look at this routine on the PickWiki website:
https://www.pickwiki.com/index.php/InputWait
Cheers,
Brian
------------------------------
Brian Speirs
Senior Analyst - Information Systems
Self Registered
Wellington NZ
Original Message:
Sent: 05-07-2023 23:12
From: Gregor Scott
Subject: Is it possible to set an input timeout for !EDIT.INPUT
I have a need to provide a user input prompt that times out gracefully after a specific period.
I am using !EDIT.INPUT
and that captures the input well.
What I am missing is a graceful method of setting a timeout for it.
I have attempted to use the AUTOLOGOUT
command.
That does trigger a logoff (an ungraceful exit but an exit non the less).
Does anyone know of a way to assign an input timeout period for !EDIT.INPUT
- or even just INPUT @
- that allows code to register and react to the non-input of data in a graceful manner?
------------------------------
Gregor Scott
Software Architect
Pentana Solutions Pty Ltd
Mount Waverley VIC AU
------------------------------