scottuk

Stop & Start Mouse Clicker Help

11 posts in this topic

Hi I am looking to improve my script.

What I need is for my mouseclicker to have a stop and start ability

So i want it to run and complete the mouse clicks for 2 hours, 

Then after 2 hours for it to stop for 2 hours,

And then continue and click for 2 hours again.

then repeat the process until i physically press ESC for it to stop doing so.

I have searched everyone and just cant seem to find the answer I am looking for.

 

Here is what i have so far. Any help is much appreciated.

Thanks in advance Scott.

HotKeySet("{ESC}", "Terminate")
While 1
MouseClick("left", 473, 625, 20, 2)
MouseClick("left", 248, 533, 1, 22)
MouseClick("left", 867, 386, 1, 15)
MouseClick("left", 630, 454, 1, 5)
MouseClick("left", 420, 431, 1, 5)
MouseClick("left", 675, 453, 355, 5) 
WEnd
Func Terminate()
    Exit 0
    EndFunc

 

Share this post


Link to post
Share on other sites



Which program do you try to automate?
MouseClick is not very reliable as it depends on screen resolution and window position. Most of the time there are more reliable ways to do what you want to do.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-02-03 - Version 1.4.7.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-03 - Version 1.2.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

i have just entered the above code into Autoit then run the script.

It works perfectly.

I just need it to run for 2 hours then pause for 2 hours then repeat ect ect.. 

Share this post


Link to post
Share on other sites

I noticed that there is no Sleep statement in your code. So your script does this 6 clicks at maximum speed.
I would add a Sleep of 1 second plus a counter. When it has reached 2 hours, add the Sleep for 2 hours and reset the counter.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-02-03 - Version 1.4.7.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-03 - Version 1.2.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You may be able to manipulate this example to get what you want.

Note: The ConsoleWrite's are present only for testing purposes, and may be commented out or deleted..

#include <Date.au3>
#include <MsgBoxConstants.au3>

Global $StartTime
Local $Diff

HotKeySet("!r", "_Reset") ; Alt + r  to reset start time.
HotKeySet("{ESC}", "Terminate")

$StartTime = _NowCalc() ; "2015/10/25 13:00:19" ; <= A test date. ;
ConsoleWrite($StartTime & @LF)

While Sleep(1000)
    $Diff = _DateDiff('n', $StartTime, _NowCalc()) ; To test, change "n" for minutes to "s" for seconds and view console for just over 6 mins.
    ConsoleWrite($Diff & "  " & Mod($Diff, 240) & "  ")

    Switch Mod($Diff, 240) ; 4hr x 60 = 240 mins
        Case 0 To 119.999999 ; 1st 2hrs  Up to 119.999999mins
            ConsoleWrite("On " & @LF)
            #cs
            MouseClick("left", 473, 625, 20, 2)
            MouseClick("left", 248, 533, 1, 22)
            MouseClick("left", 867, 386, 1, 15)
            MouseClick("left", 420, 431, 1, 5)
            MouseClick("left", 630, 454, 1, 5)
            MouseClick("left", 675, 453, 355, 5) ; <== Click 355 times?
            #ce

        Case 120 To 239.999999 ; 2nd 2hrs between 120mins and 239.999999mins
            ConsoleWrite("Off " & @LF)

    EndSwitch
WEnd


Func _Reset()
    Local $Ret = MsgBox($MB_OKCANCEL, "Select", _
            'Press "Ok" to re-initialize start time.' & @CRLF & _
            'Press "Cancel" to keep current start time.')
    If $Ret = $IDOK Then $StartTime = _NowCalc()
    ConsoleWrite($StartTime & @LF)
EndFunc   ;==>_Reset

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

 

Share this post


Link to post
Share on other sites

You may be able to manipulate this example to get what you want.

Note: The ConsoleWrite's are present only for testing purposes, and may be commented out or deleted..

#include <Date.au3>
#include <MsgBoxConstants.au3>

Global $StartTime
Local $Diff

HotKeySet("!r", "_Reset") ; Alt + r  to reset start time.
HotKeySet("{ESC}", "Terminate")

$StartTime = _NowCalc() ; "2015/10/25 13:00:19" ; <= A test date. ;
ConsoleWrite($StartTime & @LF)

While Sleep(1000)
    $Diff = _DateDiff('n', $StartTime, _NowCalc()) ; To test, change "n" for minutes to "s" for seconds and view console for just over 6 mins.
    ConsoleWrite($Diff & "  " & Mod($Diff, 240) & "  ")

    Switch Mod($Diff, 240) ; 4hr x 60 = 240 mins
        Case 0 To 119.999999 ; 1st 2hrs  Up to 119.999999mins
            ConsoleWrite("On " & @LF)
            #cs
            MouseClick("left", 473, 625, 20, 2)
            MouseClick("left", 248, 533, 1, 22)
            MouseClick("left", 867, 386, 1, 15)
            MouseClick("left", 420, 431, 1, 5)
            MouseClick("left", 630, 454, 1, 5)
            MouseClick("left", 675, 453, 355, 5) ; <== Click 355 times?
            #ce

        Case 120 To 239.999999 ; 2nd 2hrs between 120mins and 239.999999mins
            ConsoleWrite("Off " & @LF)

    EndSwitch
WEnd


Func _Reset()
    Local $Ret = MsgBox($MB_OKCANCEL, "Select", _
            'Press "Ok" to re-initialize start time.' & @CRLF & _
            'Press "Cancel" to keep current start time.')
    If $Ret = $IDOK Then $StartTime = _NowCalc()
    ConsoleWrite($StartTime & @LF)
EndFunc   ;==>_Reset

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

I tried this code with no success, this all looks almost like its too much for what i want to achieve. 

I'm completely new to coding so excuse me if i come across stupid.

I just want the code i already have to run for 2 hours then stop for 2 hours

then repeat over and over until i click ESC to make it stop.

I hope this is a possible thing, 

Thanks again in advance

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

MouseClick's.

When you say you tried the example with no success, I assume you are referring to the absence of MouseClick's.   If this be the case, then comment out the two block comment commands.  This will hide the block comment commands and reveal all the MouseCkicks commands.

Comments
To explain what this means, find the AutoIt help file and look up "#cs" or "#ce" ("#comments-start" or "#comments-end") , the block comment commands.   And notice at the bottom of the help file's example where "; #cs" and "; #ce" are used.
The semicolon (;)  is used in AutoIt scripts to add single line comments to the scripts. Everything to the right of ";" along the line is a comment.  So "; #cs" and "; #ce" actually turns the block comment commands into comments.

Notice in my posted example comments are used to hopefully add clarity to the script. So it is worthwhile reading the comments.
Also, all the ConsoleWrite commands can be line commented out or deleted in the completed script. The ConsoleWrites are there only to help understand what the script is actually doing.


The timing logic.

Every 4 hours (240 minutes) from the start of the script to the present there is 2hrs (120 minutes) on and then 2hrs (120 minutes) off.  The first 2hr on, the last 2hrs off.

 "Mod($Diff, 240)" returns where the time difference (between start time and of the present time) appears within the 4 hr cycle.  See Mod command in AutoIt help file.

 

Edited by Malkey

Share this post


Link to post
Share on other sites
$iMaxTimer = 7200000 ; 2hours in milliseconds
While True
    $iTimer = TimerInit()
    While TimerDiff($iTimer) < $iMaxTimer
        ; add in all your clicks here
    WEnd
    ; repeate the loop with no clicks
    $iTimer = TimerInit()
    While TimerDiff($iTimer) < $iMaxTimer
        ; add nothing in here
    WEnd
WEnd

 


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

scottuk,
You really should start to learn AutoIt by reading the first chapters of the help file and/or the very good tutorials in the wiki :)

It would help us to help you if you could describe why you need to automate a program in the way you try to do.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-02-03 - Version 1.4.7.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-03 - Version 1.2.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I noticed that there is no Sleep statement in your code. So your script does this 6 clicks at maximum speed.
I would add a Sleep of 1 second plus a counter. When it has reached 2 hours, add the Sleep for 2 hours and reset the counter.

How would i add that to my current code?

Im a complete noob sorry

Share this post


Link to post
Share on other sites
$iMaxTimer = 7200000 ; 2hours in milliseconds
While True
    $iTimer = TimerInit()
    While TimerDiff($iTimer) < $iMaxTimer
        ; add in all your clicks here
    WEnd
    ; repeate the loop with no clicks
    $iTimer = TimerInit()
    While TimerDiff($iTimer) < $iMaxTimer
        ; add nothing in here
    WEnd
WEnd

 

Yes!!!!!!! This is perfect and just want i wanted to achieve

Thank you so much bud, was starting to think it wasn't a possible task.

All the best brother. 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now