Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

[Easy] Autoit Wait Function?


  • Please log in to reply
9 replies to this topic

#1 MattyGibbard

MattyGibbard

    Seeker

  • Active Members
  • 42 posts

Posted 20 January 2009 - 04:11 PM

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.







#2 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,409 posts

Posted 20 January 2009 - 04:16 PM

Maybe something like this?



#3 Bam

Bam

    Wayfarer

  • Active Members
  • Pip
  • 81 posts

Posted 20 January 2009 - 05:36 PM

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, 20 January 2009 - 05:55 PM.


#4 SpookMeister

SpookMeister

    Peanut Gallery

  • Active Members
  • PipPipPipPipPipPip
  • 840 posts

Posted 20 January 2009 - 05:37 PM

Another way to do it is to use _Timer_Init() and _Timer_Diff()
Helpful tips: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.Useful links: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

<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


#5 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 20 January 2009 - 08:40 PM

....

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.
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: 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 ProgramPosted Image UDFs: 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 UDFPosted Image Examples: 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#6 FireFox

FireFox

    It slips through our fingers, like a fist full of sand.

  • MVPs
  • 5,382 posts

Posted 20 January 2009 - 10:03 PM

@MrCreator
:) not really...
While 1 Sleep(2000) ;sleeping.... MsgBox(64, 'Timer', '2sec !') WEndƒo݊÷ Ù«­¢+ؘŒÀÌØí¥¹¥Ð€ôQ¥µ•É%¹¥Ð ¤)]¡¥±”€Ä(˜ŒÀÌØ푥™˜€ôQ¥µ•É¥™˜ ˜ŒÀÌØí¥¹¥Ð¤)%˜€˜ŒÀÌØ푥™˜€™Ðìô€ÈÀÀÀÑ¡•¸)5͝  ½à Øа€˜ŒÌäíQ¥µ•È˜ŒÌä찀˜ŒÌäìÉ͕Œ€˜ŒÌÌ옌Ìäì¤(˜ŒÀÌØí¥¹¥Ð€ôQ¥µ•É%¹¥Ð ¤)¹‘%˜)QɅåQ¥À ˜ŒÌäíMÉ¥ÁИŒÌä찀˜ŒÌäí͍ɥÁЁ¥ÌÉÕ¹¹¥¹œ€˜ŒÌÌ옌Ìä찀݀Ĥ)]¹


Cheers, FireFox.

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.

Hardware : Intel® Core™ i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 07 November, 2013 - If you find dead links please send me a PM, do not post in the topics !


#7 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,251 posts

Posted 20 January 2009 - 10:18 PM

:) not really...

Not really what? You just showed what i said.
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: 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 ProgramPosted Image UDFs: 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 UDFPosted Image Examples: 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 DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#8 FireFox

FireFox

    It slips through our fingers, like a fist full of sand.

  • MVPs
  • 5,382 posts

Posted 21 January 2009 - 03:31 PM

@MrCreator
ops :lmao: missunderstood what you said :)

Cheers, FireFox.

Edited by FireFox, 21 January 2009 - 03:33 PM.

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.

Hardware : Intel® Core™ i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 07 November, 2013 - If you find dead links please send me a PM, do not post in the topics !


#9 MattyGibbard

MattyGibbard

    Seeker

  • Active Members
  • 42 posts

Posted 22 January 2009 - 02:56 AM

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.

#10 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 22 January 2009 - 03:20 AM

Plain Text         
$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, 22 January 2009 - 04:14 AM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users