Jump to content

[Easy] Autoit Wait Function?


Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Link to comment
Share on other sites

....

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.

 

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

@MrCreator

:) not really...

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

Cheers, FireFox.

Link to comment
Share on other sites

:) not really...

Not really what? You just showed what i said.

 

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

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.

Link to comment
Share on other sites

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