ex.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.
ON PEN and PEN Statements Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example uses the PEN statement to enable event trapping and the PEN
' function to display current light pen status and position. ON PEN GOSUB
' passes control to the PenReport subroutine when a pen event occurs.
 
' Note: Do not run this example if your mouse driver is enabled.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
 CLS                         ' Clear the screen
 COLOR 0, 7                  ' Set black on white
 CLS                         ' Clear the screen
 PEN ON                      ' Enable light pen
 ON PEN GOSUB PenReport
 DO
     LOCATE 23, 12
     PRINT "Press the light pen against the screen to see a report."
     LOCATE 24, 17
     PRINT "  Press the Spacebar to exit the program.     ";
 LOOP UNTIL INKEY$ = " "
 PEN OFF                     ' Disable light pen
 COLOR 7, 0                  ' Set back to black on white
 CLS                         ' Clear the screen
 END
 
PenReport:
     DO
          P = PEN(3)
          LOCATE 10, 27  ' Report light pen status and get X and Y position
          PRINT "A Pen event has occurred."
          LOCATE 24, 17
          PRINT "Press ANY key to exit the Light Pen report.";
          LOCATE 12, 30
          PRINT "Light Pen is ";
          IF P THEN
               PRINT "Down"
               X = PEN(4): Y = PEN(5)
          ELSE
               PRINT "Up  "
               X = 0: Y = 0
          END IF
          LOCATE 14, 22  ' Report the X and Y position
          PRINT "X Position ="; X; "   "
         LOCATE 14, 40
         PRINT "Y Position ="; Y; "   "
     LOOP WHILE INKEY$ = ""
     RETURN