home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a067 / 1.img / GRUMP501.EXE / INKEY.PRG < prev    next >
Encoding:
Text File  |  1991-08-07  |  3.2 KB  |  99 lines

  1. /*
  2.      Program: GINKEY()
  3.      System: GRUMPFISH LIBRARY
  4.      Author: Greg Lief
  5.      Copyright (c) 1988-90, Greg Lief
  6.      Clipper 5.x Version
  7.      Compile instructions: clipper inkey /n/w/a
  8.  
  9.      Replacement for INKEY() that tests for SET KEY procedures
  10.  
  11.      Note: you can pass an optional second parameter, which would then
  12.            get passed to the hot-key routine instead of "GINKEY"
  13. */
  14.  
  15. #include "grump.ch"
  16.  
  17. function ginkey(waittime, whatever)
  18. local key, cblock, loopy := .t.
  19. local nstart, ntimeout, bevent, bexit      // used for timeout loop
  20. do while loopy
  21.    do case
  22.       //───── if no WAITTIME passed, go straight through */
  23.       case pcount() == 0
  24.          key := inkey()
  25.       /*
  26.          dig this... if you pass inkey(NIL), it is identical to INKEY(0)!
  27.          therefore, I allow you to pass GInkey(NIL) -- hence this mild bit
  28.          of convolution
  29.       */
  30.       case (waittime == NIL .and. pcount() == 1) .or. waittime == 0
  31.          ntimeout := ginkeytime(GINKEYTIME)
  32.          nstart := seconds()
  33.          bevent := ginkeytime(GINKEYEVENT)
  34.          do while (key := inkey()) == 0 .and. seconds() - nstart < ntimeout
  35.             if bevent != NIL
  36.                eval(bevent)
  37.             endif
  38.          enddo
  39.          if key == 0                            // we timed out!
  40.             //───── if no exitevent was specified, use screen blanker
  41.             if (bexit := ginkeytime(GINKEYEXIT)) == NIL
  42.                blankscr3(-1)
  43.             else
  44.                eval(bexit)
  45.             endif
  46.             loop
  47.          endif
  48.       otherwise
  49.          key := inkey(waittime)
  50.    endcase
  51.    cblock = setkey(key)
  52.    if cblock != NIL
  53.       //───── run the code block associated with this key and pass it the
  54.       //───── name of the previous procedure and the previous line number
  55.       eval(cblock, procname(1), procline(1), ;
  56.            if(whatever == NIL, 'GINKEY', whatever))
  57.    else
  58.       loopy := .f.
  59.    endif
  60. enddo
  61. return key
  62.  
  63. //───── end function GInkey()
  64. *--------------------------------------------------------------------*
  65.  
  66. /*
  67.      Function: GInkeyTime()
  68.      Author:   Greg Lief
  69.      Copyright (c) 1991 Greg Lief
  70.      Purpose:  Retrieve or assign the number of seconds at which to
  71.                time out of the GINKEY(0) wait state due to inactivity.
  72.                This function also retrieves or assigns the event to
  73.                process in the event of such a time-out
  74.      Syntax:   GInkeyTime(<nItem> [, <newvalue>])
  75.      Params:   <nItem> is the item to poll or change.  This setting
  76.                will be changed only if <newvalue> is passed.
  77.  
  78.                1 = nSeconds (number of seconds to wait for timeout)
  79.                2 = bEvent (code block to evaluate during wait loop)
  80.                3 = bExitEvent (code block to evaluate after timeout)
  81.  
  82.      Returns:  Current setting of <nItem>
  83. */
  84. function ginkeytime(nitem, newvalue)
  85. static settings_ := { 600000, , }
  86. local ret_val
  87. if nitem != NIL
  88.    ret_val := settings_[nitem]
  89.    if newvalue != NIL
  90.       settings_[nitem] := newvalue
  91.    endif
  92. endif
  93. return ret_val
  94.  
  95. //───── end function GInkeyTime()
  96. *--------------------------------------------------------------------*
  97.  
  98. * eof inkey.prg
  99.