[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
GetMousePosition()
Return the current button pressed and coordinates
Syntax
GetMousePosition(@<nMouseX>, @<nMouseY>)
Arguments
@<nMouseX>
Integer variable to store mouse X position.
@<nMouseY>
Integer variable to store mouse Y position.
Returns
0
No buttons pressed.
1
Left button pressed.
2
Right button pressed.
3
Left + right buttons pressed.
4
Center button pressed
5
Left + center buttons pressed.
6
Right + center buttons pressed.
7
Left + right + center buttons pressed.
Remarks
GetMousePosition() reads and returns the current mouse (X,Y) location and
buttons pressed. The current mouse cursor coordinates, <nMouseX> and
<nMouseY>, must be initialized previous to the function call, that is, the
two variables must exist (see example). If <nMouseX> and <nMouseY> are not
initialized prior to making function calls, your application may operate
incorrectly. The coordinates returned are the mouse cursor hot spot which
is the tip or origin pixel of the mouse cursor arrow.
Example
A DO WHILE loop to demonstrate mouse functions loop until both left and
right mouse buttons are pressed. Indicates which mouse button pressed and
mouse cursor coords
nStatus = CheckMouse()
IF nStatus > 0
nStatus = FindVideoMode(640,480,16)
nStatus = OpenLiveMouse(320,240)
nButtons = 0
nMouseX = 0
nMouseY = 0
nOldMouseX = 0
nOldMouseY = 0
nOldButtons = 0
* Press both left and right mouse buttons simultaneously
* to exit loop
DO WHILE nButtons < 3
nButtons = GetMousePosition(@nMouseX, @nMouseY)
* print mouse coordinates at 0,0 on screen
* print mouse button status at 2,0 on screen
nMouseX = int(nMouseX)
nMouseY = int(nMouseY)
nButtons = int(nButtons)
IF nMouseX <> nOldMouseX .or. nMouseY <> ;
nOldMouseY .or. nButtons <> nOldButtons
nStatus = HideMouse()
nStatus = SunSay(0, 0, 16, 15, 0, "", ;
"Mouse Coords:")
nStatus = SunSay(0, 20, 16, 15, 0, "###", ;
str(nMouseX))
nStatus = SunSay(0, 23, 16, 15, 0, "", ", ")
nStatus = SunSay(0, 25, 16, 15, 0, "###", ;
str(nMouseY))
IF nButtons = 1
nStatus = SunSay(2, 0, 16, 15, 0, "", ;
"Left mouse button is pressed ")
ELSEIF nButtons = 2
nStatus = SunSay(2, 0, 16, 15, 0, "", ;
"Right mouse button is pressed ")
ELSEIF nButtons = 4
nStatus = SunSay(2, 0, 16, 15, 0, "", ;
"Center mouse button is pressed")
ELSE
nStatus = SunSay(2, 0, 16, 15, 0, "", ;
"No mouse buttons pressed ")
ENDIF
nStatus = ShowMouse()
nOldMouseX = nMouseX
nOldMouseY = nMouseY
nOldButtons = nButtons
ENDIF
ENDDO
nStatus = CloseLiveMouse()
TextMode()
ELSE
? "No mouse driver detected"
ENDIF
For other examples of how to use the mouse support functions, see
SUNMOUSE.PRG, an example program distributed with Sunshow Pro.
See Also: CheckMouse() CloseLiveMouse() HideMouse() LimitMouse() OpenLiveMouse() PositionMouse() SetMouseCursor() ShowMouse()
Online resources provided by: http://www.ClipX.Net --- NG 2 HTML conversion by Dave Pearson