qb45advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
KEY(n) Statement Details
  QuickSCREEN      Details      Example      Contents      Index
──────────────────────────────────────────────────────────────────────────────
KEY(n) Statement Details
 
Syntax
  KEY(n) ON
  KEY(n) OFF
  KEY(n) STOP
 
The argument n is the number of a FUNCTION key, a cursor-direction
key, or a user-defined key. See the KEY statements for information
on assigning soft-key values to FUNCTION keys. The values of n are
as follows:
 
  Value    Key
 
   1-10    The FUNCTION keys F1-F10
     11    UP
     12    LEFT
     13    RIGHT
     14    DOWN
  15-25    User-defined keys
  30-31    The FUNCTION keys F11-F12 on 101-key keyboards
 
 
LEFT, RIGHT, UP, and DOWN refer to the direction keys.
 
You can enable trapping of combination keys by using a variation of
the KEY statement:
 
  KEY n, CHR$(keyboardflag) + CHR$(scancode)
 
The argument n is in the range 15-25 to indicate a user-defined
key. The keyboardflag can be any combination of the following
hexadecimal values:
 
  Value       Key
 
  &H00        No keyboard flag
  &H01-&H03   Either SHIFT key
  &H04        CTRL
  &H08        ALT
  &H20        NUMLOCK
  &H40        CAPSLOCK
  &H80        101-key keyboard extended keys
 
You can add the values together to test for multiple shift states.
A keyboardflag value of &H12 would test for both CTRL
and ALT being pressed, for example.
 
Because key trapping assumes the left and right SHIFT keys
are the same, you can use either &H01, &H02, or &H03 to indicate a
SHIFT key. The scancode argument is a number identifying
one of the 83 keys to trap, as shown in the table below.
 
The KEY(n) ON statement enables soft-key or cursor-direction-key
event trapping by an ON KEY statement. If you specify a nonzero
line number in the ON KEY statement while trapping is enabled,
BASIC checks to see if you have pressed KEY(n). If you have, BASIC
executes the GOSUB clause in the ON KEY statement. The text that
would normally be associated with a FUNCTION key is not input.
 
When you are working in the environment, QuickBASIC tests between
statements for key presses. In stand-alone programs, you can specify
checking between lines.
 
KEY(n) OFF disables the event trap; even if an event takes place, it
is not remembered. KEY(n) STOP inhibits the event trap; that is, if
you press the specified key your action is remembered and an ON KEY
event trap is executed as soon as a KEY(n) ON statement is executed.
 
  Keyboard Scan Codes
 
            Code                      Code                      Code
  Key       in Hex        Key         in Hex        Key         in Hex
 
  ESC       01            CTRL        1D            SPACEBAR    39
  ! or 1    02            A           1E            CAPSLOCK    3A
  @ 0r 2    03            S           1F            F1          3B
  # or 3    04            D           20            F2          3C
  $ or 4    05            F           21            F3          3D
  % or 5    06            G           22            F4          3E
  ^ or 6    07            H           23            F5          3F
  & or 7    08            J           24            F6          40
  * or 8    09            K           25            F7          41
  ( or 9    0A            L           26            F8          42
  ) or 0    0B            : or ;      27            F9          43
  _ or -    0C            " or '      28            F10         44
  + or =    0D            tilde~ or `  29            NUMLOCK     45
  LEFT      0E            LEFT SHIFT  2A            SCROLL LOCK 46
  TAB       0F            | or       2B            HOME or 7   47
  Q         10            Z           2C            UP or 8     48
  W         11            X           2D            PGUP or 9   49
  E         12            C           2E            -           4A
  R         13            V           2F            LEFT or 4   4B
  T         14            B           30            5           4C
  Y         15            N           31            RIGHT or 6  4D
  U         16            M           32            +           4E
  I         17            < or ,      33            END or 1    4F
  O         18            > or .      34            DOWN or 2   50
  P         19            ? or /      35            PGDN or 3   51
  { or [    1A            RIGHT SHIFT 36            INS or 0    52
  } or ]    1B            PRTSC or *  37            DEL or .    53
  RETURN    1C            ALT         38