Community QBasic

Rebooting the QBasic we all know and love!


Project maintained by Cory Smith

PEN

Enables, disables or returns the light pen coordinates.

Syntax

As a statement:

PEN ON

PEN OFF

PEN STOP

As a function:

x = PEN(numeric_expression)

Comments

numeric_expression is an integer value (in the range 0 through 9) that specifies the information PEN returns:

PEN ON enables the PEN read function.

PEN OFF disables the PEN read function.

PEN STOP suspends trapping. It remembers the event so immediate trapping occurs when PEN ON is executed.

PEN does not work when a mouse driver is active.

The PEN function is initially off. A PEN ON statement must be executed before any PEN read function calls can be made, or a PEN read function call results in an “Illegal function call” error.

For execution speed improvements, turn the pen off with a PEN OFF statement for those programs not using the light pen.

When the pen is in the border area of the screen, the values returned will be inaccurate.

Example

PEN ON
FOR I=1 to 500
  X=PEN(0): X1=PEN(3)
  PRINT X, X1
NEXT
PEN OFF

See Also