home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
sysutils
/
errorlev
/
keywait
/
keywait.doc
next >
Wrap
Text File
|
1989-09-11
|
3KB
|
86 lines
KEYWAIT A public domain program by Jon Saxton. Please include the
source code in any further distribution of this program.
KEYWAIT.DOS Source code for old, crude version
KEYWAIT.OS2 Source code for new, refined version
KEYWAIT.EXE OS/2 protected mode executable code
KEYWAIT.DOC This 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
F1
to load
VMOS/3
.
echo Press
F2
to load
VM/386
.
echo Press
ESC
to continue
without
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.