Jump to content

Stop & Start Mouse Clicker Help


scottuk
 Share

Recommended Posts

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

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

 

Link to comment
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

 

Link to comment
Share on other sites

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
Link to comment
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.
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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

Link to comment
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. 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...