home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / KEYWAIT.ZIP / KEYWAIT.DOC next >
Text File  |  1989-09-12  |  3KB  |  86 lines

  1. KEYWAIT        A public domain program by Jon Saxton.  Please include the
  2.         source code in any further distribution of this program.
  3.  
  4.   KEYWAIT.DOS        Source code for old, crude version
  5.   KEYWAIT.OS2        Source code for new, refined version
  6.   KEYWAIT.EXE        OS/2 protected mode executable code
  7.   KEYWAIT.DOC        This file
  8.  
  9. KEYWAIT grew from an MSDOS program I wrote to help control AUTOEXEC.BAT
  10. execution.  It takes a numeric parameter on the command line (in the range
  11. 1 to 100) and waits that number of seconds for a keystroke.  If the parameter
  12. is omitted or is outside the legal range then KEYWAIT sets the timeout period
  13. to 10 seconds.
  14.  
  15. If KEYWAIT detects a function key F1 to F10 then it sets the "errorlevel"
  16. variable to a value in the range 1 to 10 corresponding to the function key.
  17. If KEYWAIT sees the ESCape key it sets errorlevel to 27.  If any other key
  18. is pressed or the timeout period expires, KEYWAIT sets errorlevel to zero.
  19. This means you can set up your AUTOEXEC.BAT file to do something sensible by
  20. default whilst providing the facility to easily vary the normal start-up
  21. process.  For example:
  22.  
  23.     @echo off
  24.     echo.
  25.     echo.
  26.     echo.
  27.     echo Press F1 to load VMOS/3.
  28.     echo Press F2 to load VM/386.
  29.     echo Press ESC to continue without DOSEDIT.
  30.     echo Press any other key (or none) to load DOSEDIT and continue.
  31.     echo.
  32.     echo.
  33.     echo.
  34.     keywait 16
  35.     if errorlevel 11 goto msdos
  36.     if errorlevel 2 goto vm386
  37.     if errorlevel 1 goto vmos3
  38.     rem Get here on a timeout or any keypress except F1, F2, ESC.
  39.     dosedit
  40.     goto msdos
  41.     :vm386
  42.     rem Get here on F2
  43.     cd vm386
  44.     vm386
  45.     rem Never return to this program
  46.     :vmos3
  47.     rem Get here on F1
  48.     cd vmos
  49.     vmos
  50.     :msdos
  51.     rem Get here directly on ESC or indirectly from DOSEDIT load.
  52.     echo on
  53.  
  54. Well that was the MSDOS version.  Just for want of something to do I recoded
  55. it for OS/2.  It is probably of less value under OS/2 than under MSDOS but it
  56. may be of use to someone.  It does provide a simple example of a multithread
  57. program.
  58.  
  59. The main program parses the command line and establishes the timeout period
  60. before forking each of the subsidiary threads.  It then waits for an event
  61. to be caused by one of the threads.
  62.  
  63. The second thread waits on a keypress and, if it gets one, sets the program's
  64. exit code and notifies the main program.
  65.  
  66. The third thread establishes a recurrent timer with a period of about one
  67. second and counts down.   If the count reaches zero then it tells the main
  68. program.
  69.  
  70. There is a small timing window which could conceivably yield the "wrong"
  71. result when a key is hit just as the timeout period expires.  This window
  72. could be resolved via a critical section but that sort of precision is not
  73. necessary in this program.
  74.  
  75. This program was written for text mode operation.  I am using OS/2 1.0.  So
  76. far I have never even seen 1.1 and I have no idea how relevant it might be
  77. in a Presentation Manager environment.  Useless, no doubt.
  78.  
  79. Assemble with MASM 5.1 or later and link with DOSCALLS.LIB.
  80.  
  81.     masm keywait.os2;
  82.     link keywait,,,doscalls;
  83.  
  84. Jon Saxton
  85. 13/9/89.
  86.