Jump to content

Slow Down Script Execution


 Share

Recommended Posts

  • Developers

Is there any way to slow down the execution of a script without putting a sleep() between every command?

check out adlib and put the sleep in there .....

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 8 months later...

Hello, I also want to slow down a script.

I made it for a rapid configuration of a fresh WinXP install.

It first imports a Reg file with major changes and after that does various things to set WXP to my like... But the script has some errors and at the speed that it flashes by the screen I can't adress them. It took me two hours to debug a little error and I have time to debug more, but I think it would be useful for everyone to have an option or way to slow down scripts (globally, not just key presses or mouse clicks; that, I know how to accomplish).

This is what I have by now:

#NoTrayIcon
If Not(@DesktopWidth="800")or Not(@DesktopHeight="600")Then
MsgBox(16,"¡Cambiá la resolución!","¡Esto sólo funciona si la resolución es de 800 x 600!")
Run("Control Desk.cpl,,3")
Exit
EndIf
Opt("SendKeyDelay",10)
Opt("SendKeyDownDelay",10)
$Aviso=MsgBox(49,"Aviso","Con este script vas a realizar las siguientes acciones:"&@LF&""&@LF&" 1. Añadir por medio del registro varios cambios en las configuraciones del Panel de control"&@LF&" 2. Modificar la configuración del Explorador de Windows"&@LF&" 3. Seleccionar el método de comprobación de la Firma de controladores y"&@LF&"    4. Cambiar la vista del Administrador de tareas.",5)
If $Aviso=2 Then Exit
DirCreate("C:\AutoItReg")
FileInstall("D:\CfgUser.reg","C:\AutoItReg\")
Run("RegEdit.exe C:\AutoItReg\CfgUser.reg")
WinWaitActive("Editor del Registro","¿Está seguro de que desea agregar la información en")
Send("S")
$RegStat1=WinGetText("Editor del Registro")
$RegStat2=StringInStr($Regstat1,"Se ha conseguido introducir la información de ")
Send("{Space}")
If $RegStat2=0 Then
MsgBox(16,"Error","No se puede importar datos al registro. Cancelando.")
FileDelete("C:\AutoItReg\CfgUser.reg")
DirRemove("C:\AutoItReg")
Exit
EndIf
FileDelete("C:\AutoItReg\CfgUser.reg")
DirRemove("C:\AutoItReg")
Send("#e")
WinWaitActive("Mi PC")
WinActivate("","Área de notificación")
Send("+{F10}I")
WinActivate("Mi PC")
Send("!{F4}#e")
WinWaitActive("Mi PC")
Send("!{Space}X!{F4}#e")
WinWaitActive("Mi PC")
Send("!VCR!VD!HO^{Tab}!AS^+{Tab}{Enter}PANEL!VXC^{NumPadAdd}")
MouseClick("Primary",35,175)
Send("!VXC!{F4}")
Run("Control SysDM.cpl,,2")
WinWaitActive("Propiedades del sistema")
Send("!FN{Enter}{Enter}^+{Esc}")
WinWaitActive("Administrador de tareas de Windows")
Send("^{Tab}!OS!OZ!VSE{NumPadAdd}I{NumPadAdd}M{NumPadAdd}{Enter}^{NumPadAdd}!M{NumPadAdd}")
WinMove("Administrador de tareas de Windows","",0,0,800,570)
MouseClickDrag("Primary",506,100,510,100)
MouseClickDrag("Primary",407,100,415,100)
MouseClickDrag("Primary",346,100,350,100)
MouseClickDrag("Primary",293,100,295,100)
WinMove("Administrador de tareas de Windows","",0,0,570,570)
Send("{Esc}")
Send("#d{Home}^{Space}+{F10}CN!{F4}")

Off topic: that is huge! I will find out, I guess, how to show code with a scroll bar as I saw in other posts. Admins, feel free to edit this first reply!

As you may see, I can just test the script by parts (as I was doing for the last two days) but this is not the problem, the truth is that I want to know how to slow down any script for an easier debug for anyone scripting. As I said, this script is for a fresh install of windows (without autoIt :D <I love it by now>) so I have to compile, save it to a floppy pass it to another PC and run it, a slow debuggin test (yes, I know there are worst things). :">

I had though of inserting a Sleep(500) between every line and raising the SendKeyDelay and SendKeyDownDelay adding more Opts for the mouse but I think that there has to be a smarter way, only that I am not that smart to dig it up! :P

Well, I better start doing what I've just posted while waiting for your kind reply.

TIA, and thanks for AutoIt that is more powerfull that I ever thought.

PS: you may notice weird words in the script. That is spanish as that is my natal language. :"> There is no need for translation as the text is mostly irrelevant.

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

Another reply, I don't want to mix this with the last one as this is not an Edit.

I was trying to understand Adlib but... All efforts were in vane.

Example:

AdlibEnable("myadlib")

;...

Exit

Func myadlib()

If WinActive("Error") Then

;...

EndIf

EndFunc

I replaced the ";..." with some code but without changes. Yes, I am really misunderstanding the whole thing but I don't get how to use the function. :D

One try:

AdlibEnable("myadlib",1000)
Run("Notepad.exe")
WinWaitActive("Sin t")
Send("a")
Send("a")
Send("a")
Send("a")
Send("a")
Send("a")
Send("a")
Send("a")
Exit
Func myadlib()
 If WinActive("Error") Then
       ;...
 EndIf
EndFunc

Second try:

AdlibEnable("myadlib",1000)
Exit
Run("Notepad.exe")
WinWaitActive("Sin t")
Func myadlib()
Send("a")
Send("a")
Send("a")
Send("a")
Send("a")
Send("a")
Send("a")
Send("a")
EndFunc

Well, that's all by now. I will be pasting Sleep(500) for a while if anyone needs me. :P

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

Link to comment
Share on other sites

Here is an example of slowing down a loop using AdlibEnable.

Opt('TrayIconDebug', 1)

AdlibEnable('adlib', 300)

Sleep(200)

For $i = 1 To 10
    ConsoleWrite(' Loop ' & $i & @CRLF)
    Sleep(100)
Next

Exit

Func adlib()
    ConsoleWrite('- Sleep(500)' & @CRLF)
    Sleep(500)
EndFunc

I have enabled Tray icon debug so you can mouve you mouse over the systray icon to see which line of code is being processed.

AdlibEnable will interrupt the above script every 300 ms to run the adlib function. The loop is paused while AdlibEnable runs the function. The output pane in Scite should show the ConsoleWrites in real time so you can understand how AdlibEnable works.

AutoIt allows some time for the loop and then runs the function. Then time for the loop again and then once again the function runs. This continues until the end of the script.

:P

Link to comment
Share on other sites

  • 2 weeks later...

Well, just to ask as I don't know if I got it right or not:

First: a very big thanks to MHz for the help.

I "wrote" this little script for testing purposes and to try to understand the function and stuff:

AdlibEnable('adlib', 500)
WinActivate("Sin título - Bloc"); Untitled - Notepad (I have that window open while testing)
Send("^e"); Select all shortcut
Sleep(5000)
Send("End")
Func adlib()
 Send("A")
 Sleep(500)
 Send("B{Enter}{Enter}")
EndFunc

And this is what it "writes":

AB

AB

AB

AB

AB

AB

AB

AB

AB

AB

EndAB

AB

When I noticed that the script writes "End" some lines before the end I began to understand and after testing it various times with different sleep times I got that every instance of the adlib function can be superimposed to each other still running and that that doesn't means that the function gets "paused", only the script does. (If the function gets paused while another instance of the same is running then one should get something like "AAB<e><e>B" but it seems to put the funtions on a queue).

Thanks in advance, Ktulu

PS: sorry, I didn't use ConsoleWrite as I script with Notepad, it works kinda fine by now and allows me to script easy on any computer. If I get used to the colors and functionalities of Scite I am afraid I will never like to script on plane notepad again :-)

PS2: Off topic ¿where is the best part to insert a Func something()? ¿At the beggining, at the end or where it is used? For easier scriting I put them where they are used (ie: OnAutoItExit; at the end).

AutoIt is a blessing, I don't know how I was able to use my computer before [Auto]It :-S

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