Jump to content

how to make function to sleep while script still running ?


Recommended Posts

for an example

Global $Paused
HotKeySet("{F7}", "TogglePause")
HotKeySet("{F8}", "Terminate")
#include <GuiConstants.au3> 
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, 'CLOSEButton')

###############################################################################################
while 1                                                                                   ##
    one()                                                                                   ##
    two()                                                                                   ##
WEnd                                                                                         ##
    Func one()                                                                             ##
        Sleep(30000) I want this to stop only function one while func two still running   ##
        Send("{F1}")                                                                         ##
        Sleep(200)                                                                         ##
        Send("x")                                                                           ##
    EndFunc                                                                               ##
                                                                                             ##
    Func two()                                                                             ##
        MouseClick(XXXX)<--- example                                                         ##
        Sleep(10000)                                                                         ##
        MouseClick(XXXX)<--- example                                                         ##
    EndFunc                                                                               ##
###############################################################################################

Func CLOSEButton()
ProcessClose("reform.exe")
exit
EndFunc
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',405,697)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    ProcessClose("reform.exe")
    Exit 0
EndFunc

if it made right ,, function two will loop 3 times before function one to work then sleep again for 30 sec while function two running

i hope its clear

ty in advance

[center][/center]My Projects:-[list][*]Window Ender[*]Encryptor-Decryptor[/list]

Link to comment
Share on other sites

Can't you just do it like this?

Global $Paused
HotKeySet("{F7}", "TogglePause")
HotKeySet("{F8}", "Terminate")
#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, 'CLOSEButton')

while 1
two()
one()
WEnd                                                                                         
    Func one()                                                                             
        Send("{F1}")
        Sleep(200)                                                                         
        Send("x")                                                                           
    EndFunc 
                                                                                            
    Func two()  
For $i = 1 to 3                                                                                 
        MouseClick(XXXX)<--- example
        Sleep(10000)                                                                         
        MouseClick(XXXX)<--- example                                                            
Next                                                                                        
    EndFunc

Func CLOSEButton()
ProcessClose("reform.exe")
exit
EndFunc
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',405,697)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    ProcessClose("reform.exe")
    Exit 0
EndFunc
Edited by poisonkiller
Link to comment
Share on other sites

thank you for your reply

i think that makes func two run 3 times befor func 1

but those numbers was for example and i'll make that time comes from GUICtrlCreateInput

like this

GuiCreate("Auto Party Script", 190,275)
GUISetOnEvent($GUI_EVENT_CLOSE, 'CLOSEButton')
$mma1=GUICtrlCreateInput($time1,3, 200, 185, 20,$ES_CENTER)
$mma2=GUICtrlCreateInput($time2,3, 250, 185, 20,$ES_CENTER)
GUICtrlSetOnEvent($Start, "StartButton")

Func StartButton()

$time1 = GUICtrlRead($mma1)
$time2 = GUICtrlRead($mma2)

GUICtrlSetData($Start,"Stop")
GUICtrlSetData($Start,"Start")
EndFunc

###############################################################################################
while 1                                                                                   ##
    one()                                                                                   ##
    two()                                                                                   ##
WEnd                                                                                         ##
    Func one()                                                                             ##
        Sleep($time1) I want this to stop only function one while func two still running     ##
        Send("{F1}")                                                                         ##
        Sleep(200)                                                                         ##
        Send("x")                                                                           ##
    EndFunc                                                                               ##
                                                                                             ##
    Func two()                                                                             ##
        MouseClick(XXXX)<--- example                                                         ##
        Sleep($time2)                                                                       ##
        MouseClick(XXXX)<--- example                                                         ##
    EndFunc                                                                               ##
###############################################################################################

how it is gonna be ??

[center][/center]My Projects:-[list][*]Window Ender[*]Encryptor-Decryptor[/list]

Link to comment
Share on other sites

Hi,

You can use AdlibEnable()...

GuiCreate("Auto Party Script", 190,275)
GUISetOnEvent($GUI_ESÐÓÔÑK  ÌÎNÐÓÔÑP]ÛÌÎNÊBÌÍÛ[XLOQÕRPÝÜX]R[]
    ÌÍÝ[YLÃ2Â#ÂRÂ#Âb33c´U5ô4TåDU"¢b33c¶ÖÖ#ÔuT7G&Ä7&VFTçWBb33c·FÖS"Ì°ÈÔÀ°ÄàÔ°ÈÀ°ÀÌØíM}
9QH¤)U%
ÑɱMÑ=¹Ù¹Ð ÀÌØíMÑÉаÅÕ½ÐíMÑÉÑutton")

Func StartButton()

$time1 = GUICtrlRead($mma1)
&#0ÍÝ[YLHÕRPÝXY
    ÌÍÛ[XLBÕRPÝÙ]]J   ÌÍÔÝ    ][ÝÔÝÜ  ]÷C²¤uT7G&Å6WDFFb33cµ7F'BÂgV÷Cµ7F'BgV÷C²¤VæDgVæ0 ¤FÆ$Væ&ÆRgVÐíÑݼÅÕ½Ðì°Ô¤()Ý¡¥±Ä(½¹ ¤)]¹(Õ¹½¹ ¤(M±À ÀÌØíime1)
        Send("{F1}")
        Sleep(200)
        Send("  ][ÝÊB[[Â[ÈÛÊ
B[ÝÙPÛXÚÊ
IËKKH^×ÆP¢6ÆVWb33c·FÖS"¢Ö÷W6T6Æ6²fÇC²ÒÒÒW×ÆP¢¹Õ¹(

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Flash reply...

You want func1 to run 1 time and func2 to stay in loop???

; ----------------------------------------------------------------------->See this:

Dim sw=1 ; <-THIS IS THE SWICH ... 1=ON; 0=OFF

GuiCreate("Auto Party Script", 190,275)

GUISetOnEvent($GUI_EVENT_CLOSE, 'CLOSEButton')

$mma1=GUICtrlCreateInput($time1,3, 200, 185, 20,$ES_CENTER)

$mma2=GUICtrlCreateInput($time2,3, 250, 185, 20,$ES_CENTER)

GUICtrlSetOnEvent($Start, "StartButton")

Func StartButton()

$time1 = GUICtrlRead($mma1)

$time2 = GUICtrlRead($mma2)

GUICtrlSetData($Start,"Stop")

GUICtrlSetData($Start,"Start")

EndFunc

while 1

one()

two()

WEnd

Func one()

IF sw=1 Then ; <- CHECK SWICH ... or IF sw Then ... **********************************

Sleep($time1) I want this to stop only function one while func two still running

Send("{F1}")

Sleep(200)

Send("x")

sw=0 ; <- SWISH FUNC OFF! *****************************************************

Endif ; *************************************************************************

EndFunc

Func two()

MouseClick(XXXX)<--- example

Sleep($time2)

MouseClick(XXXX)<--- example

EndFunc

; ------------------------------------------------------------------------------------------end.

Is this you want?

There is other ways, but this is yours. :rolleyes:

Good luck! :rambo:

Link to comment
Share on other sites

if it made right ,, function two will loop 3 times before function one to work then sleep again for 30 sec while function two running

Not sure I completely understand what you want to do, but using sleep pasues your script (everythng except events). You may want to look at timerinit() and timerdiff() instead, so that your script continues to execute, but you only send keys/mouseclicks every 'x' milliseconds. The following script sends a SPACE key every second, and an F4 key every two seconds (the small sleep at the end is to prevent consuming too many CPU cycles):

$iSpaceTimer = TimerInit
$iF4Timer = $iSpaceTimer
while 1
    If TimerDiff($iSpaceTimer) >= 1000
        WinActivate("Title of window I want to send keys to")
        send("{SPACE}")
        $iSpaceTimer = TimerInit
    EndIf
    If TimerDiff($iF4Timer) >= 2000
        WinActivate("Title of window I want to send keys to")
        send("{F4}")
        $iF4Timer = TimerInit
    EndIf
    sleep(100)
WEnd

Any use?

Link to comment
Share on other sites

thank you guys for reply i really apreciate that :rolleyes:

all your codes might work

but i found another very easy idea to do what i want to do ,, here is my code to explane

Dim $PT
GuiCreate("Auto Party Script", 190,275)
GUISetOnEvent($GUI_EVENT_CLOSE, 'CLOSEButton')
$mma1=GUICtrlCreateInput($time1,3, 200, 185, 20,$ES_CENTER)
$mma2=GUICtrlCreateInput($time2,3, 250, 185, 20,$ES_CENTER)
GUICtrlSetOnEvent($Start, "StartButton")

Func StartButton()

$time1 = GUICtrlRead($mma1)
$time2 = GUICtrlRead($mma2)

GUICtrlSetData($Start,"Stop")
GUICtrlSetData($Start,"Start")
EndFunc

###############################################################################################
while 1                                                                                   ##
    $PT= $PT+1                                                                             ##
    ToolTip($PT,865,70)                                                                   ##
    one()                                                                                   ##
    two()                                                                                   ##
WEnd                                                                                         ##
    Func one()                                                                             ##
        If $PT >= $time1 Then                                                               ##
        $PT = 0                                                                           ##
        Send("{F1}")                                                                         ##
        Sleep(200)                                                                         ##
        Send("x")                                                                           ##
        EndIf                                                                               ##
    EndFunc                                                                               ##
                                                                                             ##
    Func two()                                                                             ##
        MouseClick(XXXX)<--- example                                                         ##
        Sleep($time2)                                                                       ##
        MouseClick(XXXX)<--- example                                                         ##
    EndFunc                                                                               ##
###############################################################################################

Func CLOSEButton()
ProcessClose("reform.exe")
exit
EndFunc
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',405,697)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    ProcessClose("reform.exe")
    Exit 0
EndFunc

thank you again

Best Regards,

[center][/center]My Projects:-[list][*]Window Ender[*]Encryptor-Decryptor[/list]

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