home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol10n17.zip / ALTKEY.BAS < prev    next >
BASIC Source File  |  1991-09-12  |  1KB  |  40 lines

  1. DECLARE FUNCTION AltKey% ()
  2.  
  3. DO
  4.    K% = AltKey%
  5.    LOCATE 1, 1
  6.    PRINT TIME$
  7. LOOP UNTIL K%
  8.  
  9. IF K% > 255 THEN
  10.    PRINT "Alt was pressed alone"
  11. ELSEIF K% < 0 THEN
  12.    PRINT "Extended code"; -K%
  13. ELSE
  14.    PRINT "You pressed the"; K%; "key"
  15. END IF
  16.  
  17. FUNCTION AltKey% STATIC
  18.  
  19.     Temp$ = INKEY$                      'see if a "real" key was pressed
  20.     SELECT CASE LEN(Temp$)
  21.        CASE 1                           'if it's a regular key then
  22.           AltKey% = ASC(Temp$)          '  return its ASCII value
  23.        CASE 2                           'if it's an extended key then
  24.           AltKey% = -ASC(RIGHT$(Temp$, 1))  'negate the extended key code
  25.           AltDown% = 0                      'clear the flag that remembers Alt
  26.        CASE ELSE
  27.           AltKey% = 0
  28.           DEF SEG = 0                   'examine low memory for the Alt-key
  29.           IF PEEK(&H417) AND 8 THEN     'it's now being pressed
  30.              AltDown% = -1              'remember that Alt is now pressed
  31.             'AltKey% = 257              'use this to continuously monitor Alt
  32.           ELSEIF AltDown% THEN          '  in the calling program
  33.              AltDown% = 0
  34.              AltKey% = 256              'show that Alt alone was pressed
  35.           END IF
  36.           DEF SEG                       'restore for later PEEKs and BLOADs
  37.     END SELECT
  38.  
  39. END FUNCTION
  40.