Dec 192017
 
Nice batch file utility that waits X number of seconds, or until a function key is pressed. Answer is returned via ERRORLEVEL. DOS and OS/2 versions.
File KEYWAIT.ZIP from The Programmer’s Corner in
Category Batch Files
Nice batch file utility that waits X number of seconds, or until a function key is pressed. Answer is returned via ERRORLEVEL. DOS and OS/2 versions.
File Name File Size Zip Size Zip Type
KEYWAIT.DOC 3152 1427 deflated
KEYWAIT.DOS 3365 1347 deflated
KEYWAIT.EXE 1666 683 deflated
KEYWAIT.OS2 6052 2237 deflated

Download File KEYWAIT.ZIP Here

Contents of the KEYWAIT.DOC file


KEYWAITA public domain program by Jon Saxton. Please include the
source code in any further distribution of this program.

KEYWAIT.DOSSource code for old, crude version
KEYWAIT.OS2Source code for new, refined version
KEYWAIT.EXEOS/2 protected mode executable code
KEYWAIT.DOCThis file

KEYWAIT grew from an MSDOS program I wrote to help control AUTOEXEC.BAT
execution. It takes a numeric parameter on the command line (in the range
1 to 100) and waits that number of seconds for a keystroke. If the parameter
is omitted or is outside the legal range then KEYWAIT sets the timeout period
to 10 seconds.

If KEYWAIT detects a function key F1 to F10 then it sets the "errorlevel"
variable to a value in the range 1 to 10 corresponding to the function key.
If KEYWAIT sees the ESCape key it sets errorlevel to 27. If any other key
is pressed or the timeout period expires, KEYWAIT sets errorlevel to zero.
This means you can set up your AUTOEXEC.BAT file to do something sensible by
default whilst providing the facility to easily vary the normal start-up
process. For example:

@echo off
echo.
echo.
echo.
echo Press [32mF1[33m to load [32mVMOS/3[33m.
echo Press [32mF2[33m to load [32mVM/386[33m.
echo Press [31mESC[33m to continue [31mwithout[33m DOSEDIT.
echo Press any other key (or none) to load DOSEDIT and continue.
echo.
echo.
echo.
keywait 16
if errorlevel 11 goto msdos
if errorlevel 2 goto vm386
if errorlevel 1 goto vmos3
rem Get here on a timeout or any keypress except F1, F2, ESC.
dosedit
goto msdos
:vm386
rem Get here on F2
cd vm386
vm386
rem Never return to this program
:vmos3
rem Get here on F1
cd vmos
vmos
:msdos
rem Get here directly on ESC or indirectly from DOSEDIT load.
echo on

Well that was the MSDOS version. Just for want of something to do I recoded
it for OS/2. It is probably of less value under OS/2 than under MSDOS but it
may be of use to someone. It does provide a simple example of a multithread
program.

The main program parses the command line and establishes the timeout period
before forking each of the subsidiary threads. It then waits for an event
to be caused by one of the threads.

The second thread waits on a keypress and, if it gets one, sets the program's
exit code and notifies the main program.

The third thread establishes a recurrent timer with a period of about one
second and counts down. If the count reaches zero then it tells the main
program.

There is a small timing window which could conceivably yield the "wrong"
result when a key is hit just as the timeout period expires. This window
could be resolved via a critical section but that sort of precision is not
necessary in this program.

This program was written for text mode operation. I am using OS/2 1.0. So
far I have never even seen 1.1 and I have no idea how relevant it might be
in a Presentation Manager environment. Useless, no doubt.

Assemble with MASM 5.1 or later and link with DOSCALLS.LIB.

masm keywait.os2;
link keywait,,,doscalls;

Jon Saxton
13/9/89.


 December 19, 2017  Add comments

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)