home *** CD-ROM | disk | FTP | other *** search
- ' GETKEY.SUB -- MSDOS QuickBASIC utility subroutines
- ' by David L. Poskie Madison, WI 10 June 86
-
- '| Get Key Input Subroutines -- an interactive series
- '|
- '| Subroutines:
- '| GETKEY.PRESS -- Prompts user for keypress to continue
- '| GETKEY.CLEAR -- Clears kbd buffer & gets user response
- '| GETKEY.LOOP -- Gets a key from kbd buffer
- '| GETKEY.CAPS -- Converts an alpha ASCII char to CAPS
-
- ' Prompt the user to press a key (handy for user-released pauses)
- GETKEY.PRESS:
- LOCATE 25 , 71
- PRINT "KEYPRESS";
- GOSUB GETKEY.CLEAR
-
- RETURN
-
- ' Clear the keyboard buffer (sometimes you want no accidental response)
- GETKEY.CLEAR:
- WHILE INKEY$ <> ""
- WEND ' Falls through to GETKEY.LOOP
-
- ' Get the key input (coming directly here allows reading keyboard buffer).
- GETKEY.LOOP:
-
- '| Q$ = one ASCII character, capitalized, if alpha.
-
- LOCATE , , 1 'Turn on cursor
- Q$ = INKEY$
-
- IF Q$ = "" _
- THEN GOTO GETKEY.LOOP _
- ELSE LOCATE , , 0 ' Turn off cursor
-
- GOSUB GETKEY.CODE ' Get E.CODE & K.CODE
-
- '(Can loop to this capitalization subroutine for multi-characters.)
- GETKEY.CAPS:
-
- K.CODE = ASC(Q$)
-
- ' Capitalize any ASCII alpha character
- K.CODE = K.CODE + 32 * (K.CODE > 96 AND K.CODE < 123)
-
- ' Convert Q$ in case you want to use it in a loop
- Q$ = CHR$(K.CODE)
-
- RETURN
-
- 'Set extended code flag (E.CODE) and ASCII key code (K.CODE).
-
- GETKEY.CODE:
-
- '| Input: Q$ = one character from an INKEYS query
- '| Returns:
- '| K.CODE = ASCII key code
- '| E.CODE = 1 if extended code else E.CODE = 0
-
- IF LEFT$(Q$ , 1) = CHR$(0) _
- THEN Q$ = MID$(Q$ , 2) : _
- E.CODE = 1 _
- ELSE E.CODE = 0
-
- K.CODE = ASC(Q$)
-
- RETURN
-
- ' >>>> Physical EOF GETKEY.SUB