jessem Posted October 25, 2009 Share Posted October 25, 2009 I'm trying to figure out how to do something when the mouse moves more than a given distance in any direction. pseudo-code: $pos = MouseGetPos(); Get initial mouse pos $give0 = $pos[0] - 5 to $pos[0] + 5 ;have a little give that the mouse can move $give1 = $pos[1] - 5 to $pos[1] + 5 ;in both axis While $pos2[0]= $give0 & $pos2[1] = $give1 ;keep recording where mouse is and while it's in the space given keep recording and checking $pos2 = MouseGetPos() Sleep(100) WEnd MsgBox(0, "", "Mouse mooved Too Far") ;You blew it.. It's outside of the area given. Is there a better way to do this? Correction, what is a better way to do this? Link to comment Share on other sites More sharing options...
FuryCell Posted October 25, 2009 Share Posted October 25, 2009 This is how I would do it. $Pos = MouseGetPos(); Get initial mouse pos Dim $Pos2=$Pos While Abs($Pos[0]-$Pos2[0])<=5 and Abs($Pos[1]-$Pos2[1])<=5 $Pos2 = MouseGetPos() Sleep(100) WEnd MsgBox(0, "", "Mouse moved Too Far") Using ABS to get the absolute value so you can check that its less than or equal to 5 in both directions for each axis. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
jessem Posted October 25, 2009 Author Share Posted October 25, 2009 This is how I would do it. $Pos = MouseGetPos(); Get initial mouse pos Dim $Pos2=$Pos While Abs($Pos[0]-$Pos2[0])<=5 and Abs($Pos[1]-$Pos2[1])<=5 $Pos2 = MouseGetPos() Sleep(100) WEnd MsgBox(0, "", "Mouse moved Too Far") Using ABS to get the absolute value so you can check that its less than or equal to 5 in both directions for each axis. Hey thanks for the quick reply! I'll play around with this, thanks again! Link to comment Share on other sites More sharing options...
DW1 Posted October 25, 2009 Share Posted October 25, 2009 (edited) Gotta remember your Pythagorean theorem $distance = 50 $startX = MouseGetPos(0) $startY = MouseGetPos(1) While Sqrt(Abs(MouseGetPos(0) - $startX) ^ 2 + Abs(MouseGetPos(1) - $startY) ^ 2) < $distance Sleep(10) WEnd MsgBox(0, "", "Mouse moved beyond " & $distance & " pixels.") With GUI: #include <WindowsConstants.au3> #include <GDIPlus.au3> Global $distance = 150; Edit this for a different distance trigger Global $startX = MouseGetPos(0), $startY = MouseGetPos(1) _Main() While Sqrt(Abs(MouseGetPos(0) - $startX) ^ 2 + Abs(MouseGetPos(1) - $startY) ^ 2) < $distance Sleep(10) WEnd GUISetState(@SW_HIDE, $hGUI) _GDIPlus_Shutdown () MsgBox(0, "", "Mouse moved beyond " & $distance & " pixels.") Func _Main() Local $hGUI, $hWnd, $hGraphic ; Create GUI Global $hGUI = GUICreate("GDI+", $distance * 2 + 1, $distance * 2 + 1, $startX - $distance, $startY - $distance, $WS_POPUP,BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) $hWnd = WinGetHandle("GDI+") GUISetState() ; Draw an ellipse _GDIPlus_Startup () $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd) $hBrush = _GDIPlus_BrushCreateSolid( 0xFF00FF00 ) _GDIPlus_GraphicsFillRect($hGraphic, 0, 0, $distance * 2, $distance * 2, $hBrush) $hPen = _GDIPlus_PenCreate( 0xFFFF0000, 2) _GDIPlus_GraphicsDrawEllipse($hGraphic, 0, 0, $distance * 2, $distance * 2, $hPen) EndFunc ;==>_Main Edited October 25, 2009 by danwilli AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now