gennylk Posted July 8, 2014 Share Posted July 8, 2014 Hi There, I've had a look at some of the scripts on the forum and have prepared for following script which works. What I hoped to achieve with this is to detect no mouse movement (i.e. idle time) and move the mouse if it's idle after 30 seconds. However, I need this operation to break out of the loop if the user makes a movement - i.e. if the user makes a move while the mouse is automatically moved from A-B it should get out of the loop. (rather than move to C, D afterwards). What is the statement that suits this situation ? Thanks in advance, Genny #include <Timers.au3> ;Loop: While 1 ;Check if the idle time reached : If _Timer_GetIdleTime() >= 30 * 1000 Then MsgBox (0, "Time reached", "You have been idle for more than 30 Seconds.") MouseMove(100,100,100) ;point A MouseMove(1300,100,100) ;point B MouseMove(1300,800,100) ;point C MouseMove(100,800,100) ;point D Exit EndIf ;Sleep for 5 seconds: Sleep(2 * 1000) WEnd Link to comment Share on other sites More sharing options...
water Posted July 8, 2014 Share Posted July 8, 2014 I would check for the computer being idle before every move. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
corz Posted July 8, 2014 Share Posted July 8, 2014 Check MouseGetPos(). If the value is different from the previous check, the mouse moved! ;o) Cor nothing is foolproof to the sufficiently talented fool.. Link to comment Share on other sites More sharing options...
gennylk Posted July 8, 2014 Author Share Posted July 8, 2014 (edited) I've modified the program like this #include <Timers.au3> ;Loop: While 1 ;Check if the idle time reached : If _Timer_GetIdleTime() >= 5 * 1000 Then ;MsgBox (0, "Time reached", "You have been idle for more than 5 Seconds.") MouseMove(100,100,100) Sleep(1100) if _Timer_GetIdleTime() <1000 Then Exit Else MouseMove(1300,800,100) Sleep(1100) if _Timer_GetIdleTime() <1000 Then Exit Else MouseMove(1300,100,100) Sleep(1100) if _Timer_GetIdleTime() <1000 Then Exit Else MouseMove(100,800,100) EndIf EndIf EndIf EndIf ;Sleep for 5 seconds: Sleep(5 * 1000) WEnd Although Actually need the program to run continuously without exiting after a Mouse Move. i.e. wait in the background and check timer always, and continue. Edited July 8, 2014 by gennylk Link to comment Share on other sites More sharing options...
ScottSaltz Posted September 10, 2014 Share Posted September 10, 2014 Here is my code to move the mouse every 10 seconds IF the mouse is not "moving" at the moment. the 10 second parameter is hard coded for now. one running, click on the checkbox to "start"... I have run this on Windows7 and Windows8 with no problems. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=C:Program Files (x86)AutoIt3Iconsau3.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <array.au3> #include <ButtonConstants.au3> #include <Date.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <StaticConstants.au3> #include <StringConstants.au3> #include <Timers.au3> #include <WindowsConstants.au3> $gbTesting = True ; Create a GUI with various controls. Global $hGUI = GUICreate("Example", 300, 200) Global $iEvenOdd = 1 Global $gSeconds = 10 Global $giCalc = 1000 * $gSeconds Global $aPos, $aPos2 Global $iTotal = 0 Global $iSkipped = 0 Global $giMouseAdjustment = 1 #Region ### START Koda GUI section ### Form= $hGUI = GUICreate("Wiggle", 206, 148, 192, 125) $idCheckbox = GUICtrlCreateCheckbox("On/Off", 41, 8, 50, 17) $idCloser = GUICtrlCreateButton("Close", 15, 90, 84, 25) $Label1 = GUICtrlCreateLabel("x:", 36, 32, 45, 17, $SS_RIGHT) $Label2 = GUICtrlCreateLabel("y:", 36, 56, 45, 17, $SS_RIGHT) $Label3 = GUICtrlCreateLabel("Secs", 148, 8, 39, 17, $SS_RIGHT) $Label4 = GUICtrlCreateLabel("Total", 116, 32, 70, 17, $SS_RIGHT) $Label5 = GUICtrlCreateLabel("Skipped", 116, 56, 70, 17, $SS_RIGHT) $Label6 = GUICtrlCreateLabel("+/-", 116, 80, 70, 17, $SS_RIGHT) $Label7 = GUICtrlCreateLabel("Label7", 13, 120, 180, 17) GUICtrlSetData(-1,_now()) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) Example() Func Example() ; Loop until the user exits. Local $array, $iSecValue, $bLoop = True While $bLoop = True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idCloser ExitLoop Case $idCheckbox If _IsChecked($idCheckbox) Then _Reset() EndIf EndSwitch If _IsChecked($idCheckbox) Then $iEvenOdd = _Loop($iEvenOdd) $hStarttime = _Timer_Init() $iTimeDiff = 0 While $iTimeDiff < $giCalc $iTimeDiff=_Timer_Diff($hStarttime) $array = StringSplit($iTimeDiff,'.',$STR_ENTIRESPLIT) $left = StringLeft($array[1],1) If Number($array[1]) < 1000 Then $iSecValue = 0 Else $iSecValue = $giCalc / 1000 EndIf ;~ _ArrayDisplay($array) Switch StringLen($array[1]) Case 4 GUICtrlSetData($Label3,StringLeft($array[1],1)) Case 5 GUICtrlSetData($Label3,StringLeft($array[1],2)) Case 6 GUICtrlSetData($Label3,StringLeft($array[1],3)) EndSwitch Sleep(250) Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idCloser $bLoop = False ExitLoop Case $idCheckbox If _IsChecked($idCheckbox) Then _Reset() EndIf EndSwitch WEnd GUICtrlSetData($Label3,0) EndIf WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func _Reset() GUICtrlSetData($Label7,'Started: ' & _now()) $iTotal = 0 GUICtrlSetData($Label4,'Total: ' & $iTotal) $iSkipped = 0 GUICtrlSetData($Label5,'Skips: ' & $iSkipped) EndFunc Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Func _Loop($EvenOdd) Local $FuncName = '_Loop.' & @ScriptLineNumber Local $aPos = MouseGetPos() sleep(500) Local $aPos2 = MouseGetPos() If $aPos[0] = $aPos2[0] _ And $aPos[1] = $aPos2[1] Then If $EvenOdd = 1 Then $x = $aPos[0] + $giMouseAdjustment $y = $aPos[1] + $giMouseAdjustment Else $x = $aPos[0] - $giMouseAdjustment $y = $aPos[1] - $giMouseAdjustment EndIf GUICtrlSetData($Label1,'x: ' & $x) GUICtrlSetData($Label2,'y: ' & $y) MouseMove($x,$y) $iTotal += 1 GUICtrlSetData($Label4,'Total: ' & $iTotal) If $EvenOdd = 2 Then $EvenOdd = 1 $sign = '+' Else $EvenOdd += 1 $sign = '-' EndIf GUICtrlSetData($Label6,$sign) Else $iSkipped += 1 GUICtrlSetData($Label5,'Skips: ' & $iSkipped) EndIf Return $EvenOdd EndFunc 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