Microsoft KB Archive/32725

= PEN Function Returns Mouse Cursor Position in Basic =

Article ID: 32725

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Professional Development System 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 &quot;Microsoft QuickBasic 4.0: Basic Language Reference&quot; 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 &quot;Microsoft Mouse Programmer's Reference Guide,&quot; which can be ordered using the order blank enclosed in the Microsoft Mouse package.

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

Additional query words: QuickBas BasicCom

Keywords: KB32725

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.