Jump to content

AutoIt needs.. sleep? :p


Recommended Posts

Hey, so i just started yesterday with AutoIt and found that awesome beginner tutorial on the site ;)

I made a script:

Send("{w}")

MouseClick("left")

Send("{tab}")

Send("{w}")

MouseClick("left")

Send("{tab}")

But the script did not work propperly.. So i changed it to this:

Send("{w}")

MouseClick("left")

Send("{tab}")

Sleep(1)

Send("{w}")

MouseClick("left")

Send("{tab}")

And it worked smooth.. Was this because the program i was running it in needed 1 Mil. Sec. to respond? :D

Sorry that i can't be better to describe myself :)

Link to comment
Share on other sites

  • Moderators

Schoening,

Welcome to the AutoIt forum. :)

As you discovered , apps often need a short pause between Send commands to give them time to react. But there is no point in using a Sleep of less than 10ms - AutoIt treats them all the same as the API function it uses to pause itself has a minimum level of about that value (there are special cases like Sleep(0), but we will leave them until later. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Schoening,

As I said above, apps receiving multiple Send commands often require an intermediate Sleep to allow them to react. What I explained was that it makes no difference if you use Sleep(1) or Sleep(10) - AutoIt will give you the minimum sleep possible in either case. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

kylomas,

As far as I understand it, using Sleep(0) tells the OS that the app is ready to give up its next timeshare on the CPU. If the CPU is busy then this could be a significant delay (in computer terms) - if the CPU is pretty much idle then it could be an almost instantaneous pause. There is probably more to it - but you will have to wait for a real nerd to come along and explain further (which comment will probably prevent anyone else from doing so!). ;)

Of interest, Jon coded GUIGetMsg and TrayGetMsg in a similar manner - busy CPU means about 10ms delay; idling CPU means only just enough delay to give the CPU a break. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Schoening, If i need a delay in the range of 1 to 10 I use sleep function from kernel dll. Heres quick example:

;Open handle to kernel making call to sleep as fast as possible
$hKernel = DllOpen('kernel32.dll')
;register function that will close handle one exit
OnAutoItExitRegister('_CloseHandles')

$hTime = TimerInit()
_Sleep(1)
ConsoleWrite('Sleep(1) = ' & TimerDiff($hTime) & @LF)

$hTime = TimerInit()
_Sleep(2)
ConsoleWrite('Sleep(2) = ' & TimerDiff($hTime) & @LF)

$hTime = TimerInit()
_Sleep(3)
ConsoleWrite('Sleep(3) = ' & TimerDiff($hTime) & @LF)

$hTime = TimerInit()
_Sleep(0)
ConsoleWrite('Sleep(0) = ' & TimerDiff($hTime) & @LF)

Func _Sleep($iMs)
     DllCall($hKernel, 'none', 'Sleep', 'dword', $iMs)
EndFunc
Func _CloseHandles()
     DllClose($hKernel)
EndFunc

My results were

Sleep(1) = 1.05511285324879
Sleep(2) = 1.9529418029077
Sleep(3) = 2.99126132270029
Sleep(0) = 0.0307195124198989

Also from the msdn:

If you specify 0 milliseconds, the thread will relinquish the remainder of its time slice but remain ready. Note that a ready thread is not guaranteed to run immediately. Consequently, the thread may not run until some time after the sleep interval elapses.

Edited by Beege
Link to comment
Share on other sites

Sorry thats my bad. When I replied, I looked at post #7 and thought you were the OP. Ill edit that.

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