| .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 |