home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / quicksub / getkey.sub < prev    next >
Encoding:
Text File  |  1986-06-12  |  1.8 KB  |  71 lines

  1. ' GETKEY.SUB -- MSDOS QuickBASIC utility subroutines
  2. '        by David L. Poskie   Madison, WI   10 June 86
  3.  
  4.     '| Get Key Input Subroutines -- an interactive series
  5.     '|
  6.     '| Subroutines:
  7.     '|    GETKEY.PRESS -- Prompts user for keypress to continue
  8.     '|    GETKEY.CLEAR -- Clears kbd buffer & gets user response
  9.     '|    GETKEY.LOOP  -- Gets a key from kbd buffer 
  10.     '|    GETKEY.CAPS  -- Converts an alpha ASCII char to CAPS
  11.  
  12. ' Prompt the user to press a key (handy for user-released pauses)
  13. GETKEY.PRESS:
  14.     LOCATE 25 , 71 
  15.     PRINT "KEYPRESS";
  16.     GOSUB GETKEY.CLEAR
  17.  
  18. RETURN
  19.  
  20. ' Clear the keyboard buffer (sometimes you want no accidental response)
  21. GETKEY.CLEAR:
  22.     WHILE INKEY$ <> ""
  23.     WEND                ' Falls through to GETKEY.LOOP
  24.  
  25. ' Get the key input (coming directly here allows reading keyboard buffer).
  26. GETKEY.LOOP:
  27.  
  28.     '|    Q$ = one ASCII character, capitalized, if alpha.
  29.     
  30.     LOCATE , , 1                'Turn on cursor
  31.     Q$ = INKEY$
  32.  
  33.     IF Q$ = ""                            _
  34.        THEN GOTO GETKEY.LOOP                    _
  35.        ELSE LOCATE , , 0            ' Turn off cursor
  36.  
  37.     GOSUB GETKEY.CODE            ' Get E.CODE & K.CODE
  38.  
  39.     '(Can loop to this capitalization subroutine for multi-characters.)
  40. GETKEY.CAPS:
  41.  
  42.     K.CODE = ASC(Q$)
  43.  
  44.     ' Capitalize any ASCII alpha character
  45.     K.CODE = K.CODE + 32 * (K.CODE > 96 AND K.CODE < 123)
  46.  
  47.     ' Convert Q$ in case you want to use it in a loop
  48.     Q$ = CHR$(K.CODE)
  49.  
  50. RETURN
  51.  
  52.     'Set extended code flag (E.CODE) and ASCII key code (K.CODE).
  53.  
  54. GETKEY.CODE:
  55.  
  56.     '|  Input: Q$ = one character from an INKEYS query
  57.     '|  Returns:
  58.     '|    K.CODE = ASCII key code
  59.     '|    E.CODE = 1 if extended code else E.CODE = 0
  60.  
  61.     IF LEFT$(Q$ , 1) = CHR$(0)                    _
  62.        THEN Q$ = MID$(Q$ , 2) :                    _
  63.         E.CODE = 1                         _
  64.         ELSE E.CODE = 0
  65.  
  66.     K.CODE = ASC(Q$)
  67.  
  68. RETURN
  69.  
  70. ' >>>> Physical EOF GETKEY.SUB
  71.