home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / SINKEY.PRG < prev    next >
Text File  |  1991-08-16  |  3KB  |  96 lines

  1. /*
  2.  * File......: SINKEY.PRG
  3.  * Author....: Greg Lief
  4.  * CIS ID....: 72460,1760
  5.  * Date......: $Date:   15 Aug 1991 23:06:10  $
  6.  * Revision..: $Revision:   1.2  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/sinkey.prv  $
  8.  * 
  9.  * This is an original work by Greg Lief and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/sinkey.prv  $
  16.  * 
  17.  *    Rev 1.2   15 Aug 1991 23:06:10   GLENN
  18.  * Forest Belt proofread/edited/cleaned up doc
  19.  * 
  20.  *    Rev 1.1   14 Jun 1991 19:53:02   GLENN
  21.  * Minor edit to file header
  22.  * 
  23.  *    Rev 1.0   01 Apr 1991 01:02:18   GLENN
  24.  * Nanforum Toolkit
  25.  *
  26.  */
  27.  
  28.  
  29. /*  $DOC$
  30.  *  $FUNCNAME$
  31.  *     FT_SINKEY()
  32.  *  $CATEGORY$
  33.  *     Keyboard/Mouse
  34.  *  $ONELINER$
  35.  *     Replacement for INKEY() that tests for SET KEY procedures
  36.  *  $SYNTAX$
  37.  *     FT_SINKEY( [ <nWaitTime> ] ) -> nKey
  38.  *  $ARGUMENTS$
  39.  *     <nWaitTime> is the number of seconds to wait.  If zero,
  40.  *     FT_SINKEY() will wait indefinitely for a keypress.  If not
  41.  *     passed, FT_SINKEY() does not wait for a keypress.  If NIL,
  42.  *     it is treated the same as 0.
  43.  *  $RETURNS$
  44.  *     The INKEY() value of the key pressed.
  45.  *  $DESCRIPTION$
  46.  *     FT_SINKEY() is similar to the function provided by Nantucket in
  47.  *     KEYBOARD.PRG, with one significant difference: you can pass NIL
  48.  *     to INKEY(), which will be treated as a zero (i.e., wait indefinitely
  49.  *     for keypress).  Therefore, it is necessary to differentiate between
  50.  *     an explicit NIL and one that is a result of a formal parameter NOT
  51.  *     being received.
  52.  *
  53.  *     FT_SINKEY() differs from the standard INKEY() in that it will
  54.  *     respond to any keys set with SET KEY TO or SetKey().
  55.  *  $EXAMPLES$
  56.  *     SetKey( K_F1, {|n,l,r| Help(n,l,r) } )
  57.  *     nKey := FT_SINKEY(0)       // Help() will be called if F1 pressed
  58.  *  $END$
  59.  */
  60.  
  61.  
  62.  
  63. FUNCTION FT_SINKEY(waittime)
  64.   LOCAL key, cblock
  65.  
  66.   DO CASE
  67.  
  68.      /* if no WAITTIME passed, go straight through */
  69.      CASE pcount() == 0
  70.         key := inkey()
  71.  
  72.      /* dig this... if you pass inkey(NIL), it is identical to INKEY(0)!
  73.         therefore, I allow you to pass FT_SINKEY(NIL) -- hence this mild bit
  74.         of convolution */
  75.  
  76.      CASE waittime == NIL .AND. Pcount() == 1
  77.         key := inkey(0)
  78.  
  79.      OTHERWISE
  80.         key := inkey(waittime)
  81.  
  82.   ENDCASE
  83.  
  84.   cblock := Setkey(key)
  85.  
  86.   IF cblock != NIL
  87.  
  88.      // run the code block associated with this key and pass it the
  89.      // name of the previous procedure and the previous line number
  90.  
  91.      Eval(cblock, Procname(1), Procline(1), NIL)
  92.  
  93.   ENDIF
  94.  
  95. RETURN key
  96.