PEN Function Returns Mouse Cursor Position in Basic (32725)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0

This article was previously published under Q32725

SUMMARY

If the Microsoft MOUSE.SYS driver is installed, the PEN function gives the Microsoft Mouse cursor position in both character (row and column) and graphics (pixel) coordinates. The following values for PEN are meaningful when using the mouse, but only if both buttons are pressed:

PEN(4), PEN(5), PEN(8) and PEN(9)

You need to test if PEN(3) equals -1 to verify that both buttons are pushed.

Pages 314 and 315 of the "Microsoft QuickBasic 4.0: Basic Language Reference" manual for Versions 4.00 and 4.00b describe the values returned by the PEN function when using the mouse.

MORE INFORMATION

Please note that MOUSE CALLs provide a much better mouse interface to QuickBasic than the PEN function. MOUSE CALLs are documented in the "Microsoft Mouse Programmer's Reference Guide," which can be ordered using the order blank enclosed in the Microsoft Mouse package.

The following is a code example:
CLS
PRINT "Press both buttons to trap mouse position. Press any key to end."
DO WHILE INKEY$ = ""
        IF PEN(3) = -1 THEN
                LOCATE 10, 1
                PRINT "Row:"; PEN(8)
                PRINT "Column"; PEN(9)
                PRINT "X Pixel"; PEN(4)
                PRINT "Y Pixel"; PEN(5)
        END IF
LOOP
				

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB32725