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

  1. /*
  2.  * File......: SCANCODE.PRG
  3.  * Author....: Glenn Scott (from John Kaster)
  4.  * CIS ID....: 71620,1521
  5.  * Date......: $Date:   15 Aug 1991 23:04:32  $
  6.  * Revision..: $Revision:   1.3  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/scancode.prv  $
  8.  * 
  9.  * This is an original work by Glenn Scott and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/scancode.prv  $
  16.  * 
  17.  *    Rev 1.3   15 Aug 1991 23:04:32   GLENN
  18.  * Forest Belt proofread/edited/cleaned up doc
  19.  * 
  20.  *    Rev 1.2   14 Jun 1991 19:52:52   GLENN
  21.  * Minor edit to file header
  22.  * 
  23.  *    Rev 1.1   12 Jun 1991 02:30:32   GLENN
  24.  * Documentation mod and check for ft_int86() compatibility
  25.  * 
  26.  *    Rev 1.0   01 Apr 1991 01:02:12   GLENN
  27.  * Nanforum Toolkit
  28.  *
  29.  */
  30.  
  31.  
  32. /*  $DOC$
  33.  *  $FUNCNAME$
  34.  *     FT_SCANCODE()
  35.  *  $CATEGORY$
  36.  *     Keyboard/Mouse
  37.  *  $ONELINER$
  38.  *     Wait for keypress and return keyboard scan code
  39.  *  $SYNTAX$
  40.  *     FT_SCANCODE() -> cCode
  41.  *  $ARGUMENTS$
  42.  *     None
  43.  *  $RETURNS$
  44.  *     A two-character string, corresponding to the keyboard scan code.
  45.  *  $DESCRIPTION$
  46.  *     FT_SCANCODE() enables you to distinguish the different scancodes
  47.  *     of similar keys (such as Grey minus versus regular minus), thus
  48.  *     increasing the number of keys your input routine can recognize.
  49.  *
  50.  *     It works like INKEY(), in that it waits for a key to be pressed.
  51.  *     The scan code consists of two bytes, which are returned as a
  52.  *     two-character string.
  53.  *
  54.  *     For example, calling FT_SCANCODE() and pressing the Grey-minus
  55.  *     key will return a two character string:
  56.  *
  57.  *            CHR(45) + CHR(74)
  58.  *
  59.  *     LASTKEY() is not updated by FT_SCANCODE(), so don't try to
  60.  *     test LASTKEY() to see what was pressed during an FT_SCANCODE()
  61.  *     call.  Simply assign the return value to a variable and test
  62.  *     that (see the test driver below).
  63.  *
  64.  *     *  This was adapted from a short C routine posted by John Kaster on
  65.  *        NANFORUM.  It was written in Clipper to help demonstrate the 
  66.  *        FT_INT86 function of the Nanforum Toolkit.
  67.  *
  68.  *     This program requires FT_INT86().
  69.  *  $EXAMPLES$
  70.  *        cKey := FT_SCANCODE()
  71.  * 
  72.  *      [grey-] returns:  CHR(45) + CHR(74)
  73.  *      [-]     returns:  CHR(45) + CHR(12)
  74.  *      [grey+] returns:  CHR(43) + CHR(78)
  75.  *      [+]     returns:  CHR(43) + CHR(13)
  76.  *  $END$
  77.  */
  78.  
  79. #include "FTINT86.CH"
  80.  
  81. #define KEYB       22
  82.  
  83. #ifdef FT_TEST
  84.  
  85.   #DEFINE SCANCODE_ESCAPE   (chr(27) + chr(1))
  86.  
  87.   FUNCTION main()
  88.      LOCAL getlist, cKey
  89.      CLEAR
  90.      QOut("Press any key, ESCape to exit:")
  91.  
  92.      while .t.
  93.         cKey := FT_SCANCODE()
  94.         QOUT( "chr(" + str(asc(substr(cKey,1,1)),3) + ")+chr(" + str(asc(substr(cKey,2,1)),3) + ")" )
  95.         if cKey == SCANCODE_ESCAPE
  96.            exit
  97.         endif
  98.      end
  99.   RETURN nil
  100.      
  101. #endif
  102.  
  103. FUNCTION FT_SCANCODE()
  104.   LOCAL aRegs[ INT86_MAX_REGS ]
  105.  
  106.   aRegs[ AX ] = MAKEHI( 0 )
  107.   FT_INT86( KEYB, aRegs )
  108.   RETURN ( chr(LOWBYTE( aRegs[AX] )) + chr(HIGHBYTE( aRegs[AX] )) )
  109.