Jump to content

Sleep() - Walk round?


Delta01
 Share

Recommended Posts

Hi,

I'm making a script that:

Does something

Sleeps for 10 minutes

But, while it's sleeping needs to check if a pixel changes and if so end the sleep

I've tried making a thousand smaller sleeps, each were about 750 milliseconds but the script is still in-responsive. I thought that'd make it look out for the pixel change and also detect GUI action (of course with a 750 millisecond delay)

Sorry if I'm not making much sense, I basically want to know if there's another way I can get the script to wait for 10 minutes before repeating what it does (Eg. Send 1) but whilst it's waiting still enable GUI events and Pixel detection.

Any ideas? I'm stumped.

Thanks

Link to comment
Share on other sites

Hi,

I'm making a script that:

Does something

Sleeps for 10 minutes

But, while it's sleeping needs to check if a pixel changes and if so end the sleep

I've tried making a thousand smaller sleeps, each were about 750 milliseconds but the script is still in-responsive. I thought that'd make it look out for the pixel change and also detect GUI action (of course with a 750 millisecond delay)

Sorry if I'm not making much sense, I basically want to know if there's another way I can get the script to wait for 10 minutes before repeating what it does (Eg. Send 1) but whilst it's waiting still enable GUI events and Pixel detection.

Any ideas? I'm stumped.

Thanks

AdlibEnable ( "function" [, time] )

Link to comment
Share on other sites

You may have to put your pixel check into a function and then check the function using Adlib in the GUI Msg loop. Post what you have so someone can take a look at it and tell you for sure.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

You may have to put your pixel check into a function and then check the function using Adlib in the GUI Msg loop. Post what you have so someone can take a look at it and tell you for sure.

Do
ToolTip("AFK_Weaponchanger is running. Press F6 to close", 0, 0)
If $BotProg = "iSROBOT" Then
send("{END}")
ElseIf $BotProg = "Tbot" Then
send("{F7}")
EndIf
sleep(1100)
If $Read5 = "F1" Then
    send($Bar1)
ElseIf $Read5 = "F2" Then
    send($Bar2)
ElseIf $Read5 = "F3" Then
    send($Bar3)
ElseIf $Read5 = "F4" Then
    send($Bar4)
EndIf
sleep(500)
If GUICtrlRead($check) = $GUI_CHECKED Then
Send("{CTRLDOWN}")
Send("{ALTDOWN}")
sleep(100)
Send("{1}")
Send("{CTRLUP}")
Send("{ALTUP}")
Send($Read1)
Send($Read1)
Send($Read1)
sleep(1500)
EndIf
If GUICtrlRead($check) = $GUI_CHECKED Then
Send("{CTRLDOWN}")
Send("{ALTDOWN}")
sleep(100)
Send("{1}")
Send("{CTRLUP}")
Send("{ALTUP}")
Send($Read3)
Send($Read3)
Send($Read3)
sleep(5000)
EndIf
If GUICtrlRead($check) = $GUI_CHECKED Then
If $Read4 <> "N/A" Then
Send("{CTRLDOWN}")
Send("{ALTDOWN}")
sleep(100)
Send("{1}")
Send("{CTRLUP}")
Send("{ALTUP}")
Send($Read4)
Send($Read4)
Send($Read4)
sleep(5000)
EndIf
EndIf
If GUICtrlRead($check) = $GUI_CHECKED Then
Send("{CTRLDOWN}")
Send("{ALTDOWN}")
sleep(100)
Send("{1}")
Send("{CTRLUP}")
Send("{ALTUP}")
Send($Read2)
Send($Read2)
Send($Read2)
sleep(1500)
EndIf
If $iShield <> "N/A" Then
Send("{CTRLDOWN}")
Send("{ALTDOWN}")
sleep(100)
Send("{1}")
Send("{CTRLUP}")
Send("{ALTUP}")
    send($iShield)
    send($iShield)
    send($iShield)
EndIf
    If GUICtrlRead($check) = $GUI_CHECKED Then
    If $Read6 <> "N/A" Then
Send("{CTRLDOWN}")
Send("{ALTDOWN}")
sleep(100)
Send("{1}")
Send("{CTRLUP}")
Send("{ALTUP}")
    send($Read6)
    send($Read6)
    send($Read6)
    sleep(5000)
    Endif
    If GUICtrlRead($check) = $GUI_CHECKED Then
    If $Read7 <> "N/A" Then
Send("{CTRLDOWN}")
Send("{ALTDOWN}")
sleep(100)
Send("{1}")
Send("{CTRLUP}")
Send("{ALTUP}")
Send($Read7)
    Send($Read7)
    Send($Read7)
    sleep(5000)
    EndIf
EndIf
EndIf
If $BotProg = "iSROBOT" Then
send("{INSERT}")
ElseIf $BotProg = "Tbot" Then
send("{F6}")
EndIf
If GUICtrlRead($check) = $GUI_CHECKED Then
sleep($waiting)
EndIf
ToolTip("", 0, 0)
Until GuiCtrlRead($check) = $GUI_UNCHECKED

This is my Do..Until statement. It does something, then waits.

Thanks for the fast responses btw!

EDIT: Also, is there a way to cancel a sleep during the sleep? So, while it's sleeping if something happens then cancel the sleep?

Edited by Delta01
Link to comment
Share on other sites

Hi,

I'm making a script that:

Does something

Sleeps for 10 minutes

But, while it's sleeping needs to check if a pixel changes and if so end the sleep

I've tried making a thousand smaller sleeps, each were about 750 milliseconds but the script is still in-responsive. I thought that'd make it look out for the pixel change and also detect GUI action (of course with a 750 millisecond delay)

Sorry if I'm not making much sense, I basically want to know if there's another way I can get the script to wait for 10 minutes before repeating what it does (Eg. Send 1) but whilst it's waiting still enable GUI events and Pixel detection.

Any ideas? I'm stumped.

Thanks

Saying your script needs to do things while it sleeps is rather oxymoronic. All you really want is a loop with a timer:

HotKeySet("{ESC}", "_Quit")

$iTimer = TimerInit()
$iPxColor = PixelGetColor(100, 200)
While 1
    ; Exit loop after 10min
    If TimerDiff($iTimer) > 10 * 60 * 1000 Then ExitLoop
    ; Notice if pixel changes
    If PixelGetColor(100, 200) <> $iPxColor Then
        $iPxColor = PixelGetColor(100, 200)
        MsgBox(64, "Change", "Pixel changed color to: 0x" & Hex($iPxColor, 6), 3)
    EndIf
    Sleep(50) ; This sleep keeps the loop from pegging the CPU
WEnd

Func _Quit()
    Exit
EndFunc   ;==>_Quit

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...