Jump to content

Simple question, How to click during sleep?


 Share

Recommended Posts

I have a very easy question I simply don't know the answer to and really hope for a quick answer. How can I click during a loooong sleep? Here is my sleep:

Sleep(3581600)

I want to click the left mouse button every 1 minute during that sleep and that sleep alone. Thanks in advance!

Edited by kjpolker
Link to comment
Share on other sites

I have no idea what you are trying to do but you can't really do much while you are in sleep because ... its in sleep!

The scripts displayed sleep click then sleep instead of sleeping and clicking.

Try something different

While 1
    ;do nothing. This keeps the script going
WEnd

AdlibEnable("FooFunc", 5000) ; where 5000 = your "sleep" time

Func FooFunc()
    MouseClick("left")
    ; or whatever
EndFunc   ;==>FooFunc

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

... you can't really do much while you are in sleep because ... its in sleep! ...

AdlibEnable interrupts the sleep in the While/WEnd loop shown below... so you can do lots of things in the Func called by the AdLib. But you need to place the AdLibEnable before the While/WEnd :-)

AdlibEnable("ClickFunc", 1000 * 60)

While 1
    Sleep(2147483647);do nothing. This keeps the script going
WEnd

Func ClickFunc()
    TrayTip('', 'replaces the mouse click', 10)
    Sleep(800)
    TrayTip('', '', 1)
EndFunc ;==>ClickFunc
Notice the stupidly long sleep. Your code did not have any sleep in the While/WEnd loop. I don't know if this was a typo or you thought that the script would not click "during the sleep". Test the code above. Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

AdlibEnable interrupts the sleep in the While/WEnd loop shown below... so you can do lots of things in the Func called by the AdLib. But you need to place the AdLibEnable before the While/WEnd :-)

AdlibEnable("ClickFunc", 1000 * 60)

While 1
    Sleep(99999999999);do nothing. This keeps the script going
WEnd

Func ClickFunc()
    TrayTip('', 'replaces the mouse click', 10)
    Sleep(800)
    TrayTip('', '', 1)
EndFunc ;==>ClickFunc
Notice the stupidly long sleep. Your code did not have any sleep in the While/WEnd loop. I don't know if this was a typo or you thought that the script would not click "during the sleep". Test the code above.

It looks to me like picea892 gave the only reply which satisfied what was asked for and everyone else, including the OP, has ignored it.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

It looks to me like picea892 gave the only reply which satisfied what was asked for and everyone else, including the OP, has ignored it.

Not everyone :-)

I was working my way up the thread.

I was going to comment on some of the code and then give picea892 a

Ding, ding, ding - we have a winner

...but ya beat me to it.

I got side tracked when I noticed that not only had I exceeded the limit for a sleep, but I landed on a value that is ignored. It is as if there was no sleep at all.

;Maximum sleep time is 2147483647 milliseconds (24 days).
While 1
    ;Sleep(99999) ;fine for me
    ;Sleep(9999999) ;fine for me
    ;Sleep(99999999) ;fine for me
    ;Sleep(999999999) ;fine for me
    ;Sleep(2147483647) ;fine for me
    ;Sleep(9999999999) ;fine for me
    ;Sleep(99999999999) ;fine for me
    Sleep(999999999999) ;more than 50% CPU
    ;Sleep(999999999999) ;fine for me
    ;Sleep(99999999999999) ;fine for me
WEnd
Of course, unpredictable results are expected when limits are exceeded.Your mileage may vary with the code above.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Adlibenable("clicker",60000)
Sleep(3581600)
Adlibdisable()

Func clicker()
MouseClick ("left")
EndFunc

I think that I'll skip commenting on the rest of the code in this thread and will mention that (like martin said) you came the closest to giving the OP what was requested. Of course we all know that "what was requested" and "what is needed" are often two different things.

Since the OP is using such a large sleep and since the time in the OP is 59.9 minutes, then one might infer that some level of accuracy is needed for this script. If that is indeed the case, then the code should move towards the TimerInit/TimerDiff functions.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I was went to bed early last night and have long days, I appreciate all the replies and as requested here is the entire script:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

AutoItSetOption("SendKeyDelay", 45)

HotKeySet( "{PAUSE}", "TogglePause")
Global $Paused

While 1
    WinActivate('[TITLE:World of Warcraft]')
    WinWaitActive('[TITLE:World of Warcraft]')
    Sleep(500)
    MouseClick("Left", 1292, 184, 1, 10)
    Sleep(200)
    MouseClick("Left", 718, 828, 1, 10)
    Sleep(15000)
    MouseClick("Left", 919, 575, 1, 10)
    Sleep(200)
    Send('/run SetBinding("F1", "INTERACTTARGET"){ENTER}')
    Sleep(200)
    Send('/target Amisi Azuregaze{ENTER}')
    Sleep(200)
    Send('{F1}')
    Sleep(1000)
    Send('/run SelectGossipOption(1){ENTER}')
    Sleep(1000)
    Send('/use Treat Bag{ENTER}')
    Sleep(1000)
    If ProcessExists("WoW.exe") Then
        Send('/camp{ENTER}')
    EndIf
    sleep($x)
WEnd
    For $x = 3600000 To 1 Step -1
        ToolTip ("Sleeping for " & Int ($x/60000) & " more minutes", 0, 0)
        MouseClick ("left")
        Sleep(1000)
    Next

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

The reason the sleep is a very awkward number is because I want the script to act every hour, but in my while I have some sleep commands already in there so I subtracted them from 1 hour to make it a precise 1 hour before the script starts again. So I am using Picea892's script?

Link to comment
Share on other sites

I was went to bed early last night and have long days, I appreciate all the replies and as requested here is the entire script:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.0.0
 Author: myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

AutoItSetOption("SendKeyDelay", 45)

HotKeySet( "{PAUSE}", "TogglePause")
Global $Paused

While 1
    WinActivate('[TITLE:World of Warcraft]')
    WinWaitActive('[TITLE:World of Warcraft]')
    Sleep(500)
    MouseClick("Left", 1292, 184, 1, 10)
    Sleep(200)
    MouseClick("Left", 718, 828, 1, 10)
    Sleep(15000)
    MouseClick("Left", 919, 575, 1, 10)
    Sleep(200)
    Send('/run SetBinding("F1", "INTERACTTARGET"){ENTER}')
    Sleep(200)
    Send('/target Amisi Azuregaze{ENTER}')
    Sleep(200)
    Send('{F1}')
    Sleep(1000)
    Send('/run SelectGossipOption(1){ENTER}')
    Sleep(1000)
    Send('/use Treat Bag{ENTER}')
    Sleep(1000)
    If ProcessExists("WoW.exe") Then
        Send('/camp{ENTER}')
    EndIf
    sleep($x)
WEnd
    For $x = 3600000 To 1 Step -1
        ToolTip ("Sleeping for " & Int ($x/60000) & " more minutes", 0, 0)
        MouseClick ("left")
        Sleep(1000)
    Next

Func TogglePause()
 $Paused = NOT $Paused
 While $Paused
 sleep(100)
 ToolTip('Script is "Paused"',0,0)
 WEnd
 ToolTip("")
EndFunc

The reason the sleep is a very awkward number is because I want the script to act every hour, but in my while I have some sleep commands already in there so I subtracted them from 1 hour to make it a precise 1 hour before the script starts again. So I am using Picea892's script?

I think so. Take note of herewasplato's comments though.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

... So I am using Picea892's script?

No - the code that you have in there now is from exodius and it clicks every second and it is based on the sleep function.

Look at post #2.

picea892 gave you the code that you asked for...

> "I want to click the left mouse button every 1 minute during that sleep and that sleep alone"

But the code that you asked for will not be very accurate. In other words, it might wait 61 minutes or 58 minutes. You mentioned sleep, picea892 gave you code using sleep. If you can live with a few minutes here and there then using the sleep function is fine.

Since this is for a game (I kinda thought that it was) I'll let others help you use/place the code that people are offering you or better yet, move you towards using the TimerInit/TimerDiff functions.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

AdlibEnable interrupts the sleep in the While/WEnd loop shown below... so you can do lots of things in the Func called by the AdLib. But you need to place the AdLibEnable before the While/WEnd :-)

AdlibEnable("ClickFunc", 1000 * 60)

While 1
    Sleep(2147483647);do nothing. This keeps the script going
WEnd

Func ClickFunc()
    TrayTip('', 'replaces the mouse click', 10)
    Sleep(800)
    TrayTip('', '', 1)
EndFunc ;==>ClickFunc
Notice the stupidly long sleep. Your code did not have any sleep in the While/WEnd loop. I don't know if this was a typo or you thought that the script would not click "during the sleep". Test the code above.

herewasplato - it was a typeo - AdlibEnable needs to be up top. I was cutting and pasting form some existing code.

The original script used While 1 to keep the script running whilst continually search a log file because the log file is continuously being updated. Sleep uses much less cpu then while 1 - thanks!

From the help file "Pause script execution" so I assumed you could not do anything while the script was paused. Didn't know AdlibEnable could be used to overwrite that.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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...