Returns the current x and y position of the mouse in pixels relative to the upper left corner of the current form and/or Desktop.
x% = MouseSX
y% = MouseSY
x% = Screen.MouseX
y% = Screen.MouseY
x%, y%:ivar
MouseSX and MouseSY are shortcuts for the Screen properties MouseX, MouseY and return the mouse coordinates within the desktop.
OpenW 1, 100, 100, 200, 200, 0
Local ax%, ay%, mx%, my%
Do
Sleep
ax% = mx%, ay% = my%
mx% = MouseSX, my% = MouseSY
If (ax% <> mx%) || (ay% <> my%)
Text 10, 10, "Mouse moving on the screen in"
Text 10, 30, "X-direction" + Space(20) + "Y-direction"
Text 10, 50, Space$(999)
Text 20, 50, Str$(mx%) + Space(30) + Str$(my%)
If mx% - 2 < TwipsToPixelX(Win_1.Left) Or mx% + 2 > TwipsToPixelX(Win_1.Left + Win_1.Width) Or _
my% - 2 < TwipsToPixelY(Win_1.Top) Or my% + 2 > TwipsToPixelY(Win_1.Top + Win_1.Height)
Text 10, 90, Space$(999)
Text 10, 110, Space$(999)
Text 10, 130, Space$(999)
EndIf
EndIf
Loop Until MouseK = 2
CloseW 1
Sub Win_1_MouseMove(Button&, Shift&, x!, y!)
Text 10, 90, "Mouse moving in the window at"
Text 10, 110, "X-direction" + Space(20) + "Y-direction"
Text 10, 130, Space$(999)
Text 20, 130, Str$(x!) + Space(30) + Str$(y!)
EndSub
The MouseSX and MouseSY internally call the Windows function GetCursorPos() and therefore require no PeekEvent, GetEvent or Sleep.
{Created by Sjouke Hamstra; Last updated: 19/10/2014 by James Gaite}