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.
Selected Event and Error Trapping Example Programs
◄Selected Programs► ◄Trapping Programs► ◄Contents► ◄Index►
──────────────────────────────────────────────────────────────────────────────
Event and Error Trapping
The following program shows how to trap an event that occurs while a
program is running. With event trapping, you can get your program to
detect run-time events such as keystrokes.
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
' 75 = scan code for LEFT arrow key
'
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