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.
PEN Statements Programming 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.
CLS 'Clear screen.
COLOR 0, 7 'Set black on white.
CLS 'Clear 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 Space Bar to exit the program. ";
LOOP UNTIL INKEY$ = " "
PEN OFF 'Disable light pen.
COLOR 7, 0 'Set back to black on white.
CLS 'Clean up the screen.
END
PenReport:
DO
P = PEN(3)
'Report light pen status and get X and Y position.
LOCATE 10, 27
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
'Report the X and Y position.
LOCATE 14, 22
PRINT "X Position ="; X; " "
LOCATE 14, 40
PRINT "Y Position ="; Y; " "
LOOP WHILE INKEY$ = ""
RETURN