Yes, it is used with ON KEYl...

by Pete (Login The-Universe)
Admin

 
I recall many years ago before I learned INKEY$, I thought I could escape a LINE INPUT statement with ON KEY, but not so...

CLS
KEY 15, CHR$(0) + CHR$(1)
ON KEY(15) GOSUB 10
KEY(15) ON
LINE INPUT "If you press Esc, nothing happens until after you press Enter! ";
DO
PRINT "You're in an endless loop. Press Esc and ON KEY will save your ASCII."
LOOP

10
SYSTEM
RETURN

---------------------

What happens is if you press Esc during the input statement, nothing happens until you hit Enter, then it kicks in and bypasses the endless loop! Pretty worthless. It will break you out of the endless loop though.

QB HELP provides ths example...

Example 1 - Event Trapping

If you use a 101-key keyboard, you can trap any of the keys on the
dedicated keypad by assigning the string

  CHR$(128) + CHR$(scancode)

to any of the keynumber values from 15 to 25.

The next example shows how to trap the LEFT direction keys on both
the dedicated cursor keypad and the numeric keypad.

  ' 128 = keyboard flag for keys on the
  '       dedicated cursor keypad
KEY 15, CHR$(128) + CHR$(75)    ' Trap LEFT key on
ON KEY(15) GOSUB CursorPad      ' the dedicated
KEY(15) ON                      ' cursor keypad.

ON KEY(12) GOSUB NumericPad     ' Trap LEFT key on
KEY(12) ON                      ' the numeric keypad.

DO
LOOP UNTIL INKEY$ = "q"          ' Idle loop
END

CursorPad:
  PRINT "Pressed LEFT key on cursor keypad."
RETURN

NumericPad:
  PRINT "Pressed LEFT key on numeric keypad."
RETURN

-----------------------------

Keyboard Scan Codes

ESC         01    U            16   | or        2B   F6          40
! or 1      02    I            17   Z           2C   F7          41
@ or 2      03    O            18   X           2D   F8          42
# or 3      04    P            19   C           2E   F9          43
$ or 4      05    { or [       1A   V           2F   F10         44
% or 5      06    } or ]       1B   B           30   NUMLOCK     45
^ or 6      07    ENTER        1C   N           31   SCROLL LOCK 46
& or 7      08    CTRL         1D   M           32   HOME or 7   47
* or 8      09    A            1E   < or ,      33   UP or 8     48
( or 9      0A    S            1F   > or .      34   PGUP or 9   49
) or 0      0B    D            20   ? or /      35   -           4A
_ or -      0C    F            21   RIGHT SHIFT 36   LEFT or 4   4B
+ or =      0D    G            22   PRTSC or *  37   5           4C
LEFT        0E    H            23   ALT         38   RIGHT or 6  4D
TAB         0F    J            24   SPACEBAR    39   +           4E
Q           10    K            25   CAPSLOCK    3A   END or 1    4F
W           11    L            26   F1          3B   DOWN or 2   50
E           12    : or ;       27   F2          3C   PGDN or 3   51
R           13    " or '       28   F3          3D   INS or 0    52
T           14      or `       29   F4          3E   DEL or .    53
Y           15    LEFT SHIFT   2A   F5          3F

Posted on Dec 17, 2009, 10:07 PM

Respond to this message   

Return to Index

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement