Sign in to follow this  
Followers 0

[Easy] Autoit Wait Function?

10 posts in this topic

Posted

Hey everyone, I'm new to Autoit so bare with me a second.

I have created a few simple programs but nothing overly amazing. One problem I keep coming across is setting Autoit to wait.

I know there is a sleep function such as:

"Sleep (1000)"

but this pauses the whole script for that period of time so the user cannot exit or press another button.

Is there a way to wait instead of sleep?

Example:

Let's say when I press a button, a picture shows. Easy huh? The picture only stays up for 5 seconds, and then vanishes again. So far so good. The only problem is, if I use 'Sleep' then the whole program will freeze for five seconds.

Can anyone help?

Thank you.

Share this post


Link to post
Share on other sites



Posted

Maybe something like this?

while winexists()
sleep(20)
wend

; or
while processexists()
sleep(20)
wend

Share this post


Link to post
Share on other sites

Posted (edited)

maybe like a counter like

$Count = 0
While $Count < 50
	$Count += 1
	Sleep(100)
WEnd
MsgBox(1, "Done", "sleept for 5 seconds")

giving you a count of 50 after 5 seconds maybe

(but might be longer then 5 seconds)

Edited by Bam

Share this post


Link to post
Share on other sites

Posted

Another way to do it is to use _Timer_Init() and _Timer_Diff()

Share this post


Link to post
Share on other sites

Posted

....

I know there is a sleep function such as:

"Sleep (1000)"

but this pauses the whole script for that period of time so the user cannot exit or press another button.

Is there a way to wait instead of sleep?

Example:

Let's say when I press a button, a picture shows. Easy huh? The picture only stays up for 5 seconds, and then vanishes again. So far so good. The only problem is, if I use 'Sleep' then the whole program will freeze for five seconds.

....

What you need to wait for?

P.S

Using timers or loops it's the same as Sleep(), unless you need to do something inside those loops/timer functions.

Share this post


Link to post
Share on other sites

Posted

@MrCreator

:) not really...

While 1
Sleep(2000) ;sleeping....
MsgBox(64, 'Timer', '2sec !')
WEndoÝ÷ Ù«­¢+ØÀÌØí¥¹¥ÐôQ¥µÉ%¹¥Ð ¤)]¡¥±Ä(ÀÌØí¥ôQ¥µÉ¥ ÀÌØí¥¹¥Ð¤)%ÀÌØí¥ÐìôÈÀÀÀÑ¡¸)5Í	½à ØаÌäíQ¥µÈÌäì°ÌäìÉÍÌÌìÌäì¤(ÀÌØí¥¹¥ÐôQ¥µÉ%¹¥Ð ¤)¹%)QÉåQ¥À ÌäíMÉ¥ÁÐÌäì°ÌäíÍÉ¥ÁÐ¥ÌÉÕ¹¹¥¹ÌÌìÌäì°Ä°Ä¤)]¹

Cheers, FireFox.

Share this post


Link to post
Share on other sites

Posted

:) not really...

Not really what? You just showed what i said.

Share this post


Link to post
Share on other sites

Posted (edited)

@MrCreator

ops :lmao: missunderstood what you said :)

Cheers, FireFox.

Edited by FireFox

Share this post


Link to post
Share on other sites

Posted

Thanks everyone for the info. I'm still having trouble getting it into my code.

Here is an example of what I'm doing:

-I have a GUI, a button and an image

-The image is of me

-I want to be able to change that image every 5 seconds to a blink and back again (Really fast)

-In the meantime, I still want my GUI to respond to the button press.

Thank you for any more help.

Share this post


Link to post
Share on other sites

Posted (edited)

$GUI = GUICreate ("Sample GUI", 200, 200)
$pic = GUICtrlCreatePic ("open.jpg", 10, 10, 180, 180)
GUISetState ()

$blink = False
$timer = TimerInit ()
While 1
	$nMsg = GUIGetMsg ()
	Switch $nMsg
		Case - 3
			Exit
	EndSwitch
	If TimerDiff($timer) >= 5000 Then;5 Seconds
		$timer = TimerInit()
		$blink = True
	;Switch image
		GUICtrlSetImage ($pic, "close.jpg")
	ElseIf ($blink = True) And (TimerDiff($timer) >= 100) Then
	;Switch Image Back
		GUICtrlSetImage ($pic, "open.jpg")
		$blink = False
	EndIf
WEnd

Maybe like that? (Untested)

EDIT:

Changed example.

You need the following images:

I'm fairly happy with how this works too :)

Open.JPG

Posted Image

Close.JPG

Posted Image

Edited by BrettF

Share this post


Link to post
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
Sign in to follow this  
Followers 0