Sign in to follow this  
Followers 0
huldu

GUI's along with Sleep()?

20 posts in this topic

#1 ·  Posted (edited)

Ive just been wondering, without GUICtrlSetOnEvent, how do you make the script not sluggish down?

Everytime a sleep() is brought up, for say over 1-2 seconds this affects the script pretty badly overall. Clicking on buttons or just doing stuff in the program will be a big delay (because of the sleep()). I cant figure out another way to force buttons to be a priority over any other "loop" or sleep() running in the script witout GUICtrlSetOnEvent.

Its not possible to run 2 things at same time, or is it?. For example, the main program checks whenever buttons, or text is input in the program, while another thing is doing loops and sleep()'s without interfering with the main script.

I maybe wasnt too clear on this topic tho, i could try explain more in detail! :P

-- Edit

The only way i can think possible to do anything like this would be to run a second program(?)

Edited by huldu

"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites



No.

???? What sort of answer is this ?


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

I'll elaborate in more than 3 characters for ya :P.

Your talking of MultiThreading, and at the moment AutoIt does not have that capability. But you do have a couple of options.

1. You're already doing it, using a well placed AdlibEnable() could help in some situations.

2. I just make another script, and pass the commands at run() time and if I need to get more detailed and have them interact, I use HotKeySet() and a mutal File/Ini for them to read from eachother.

Hope this helps you a bit.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

???? What sort of answer is this ?

He only get's 3 characters per post BigDod!!, soon he'll be able to complete an actual sentence :P


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

He only get's 3 characters per post BigDod!!, soon he'll be able to complete an actual sentence :P

I thought I was short of words sometimes. :lmao:


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Cool:

2. I just make another script, and pass the commands at run() time and if I need to get more detailed and have them interact, I use HotKeySet() and a mutal File/Ini for them to read from eachother.

Something like this would work great i think. I just need to figure out *cough* how *cough* to do it. How do you mean with pass commands at run() and the use of HotKeySet().

Im still stuck with the freezing part in my script cause of the FileOpenDialog thing, ive been thinking to solve this problem i would haveto use another script to run as some sort of secondary (which takes care of the game issues) while the first script takes care of running the GUI.

-- Edit

Would i haveto use 2 .exe's or can i run a second script in any other way?

The main script would take care of all the practical stuff like checking if buttons are pressed in the main script, and the secondary script would then take care of running all the side stuff. Like checking pixels, doing sleep() and loops i wouldnt want to interfere with the main script.

I have just a weebit problem to "visualize" how this would work atm :P

Edited by huldu

"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

I've never tried the $CmdLine[0] approach, maybe someone else can give you an example of that here, but I can show you a brief example of what I do.

Script One... (Do a test one, just to see the examples work... Be sure to change the path to the real paths though :P )

$VariableValueToPass = EnvSet("ThisWillBeOnTheOtherScript", "You will see this exact string in the other scripts MsgBox()")
Run("PathToTheOtherExe" & " " & $VariableValueToPass)

Script 2 (also will be compiled to an .exe)

Global $ValueFromOtherExe = EnvGet("ThisWillBeOnTheOtherScript")
MsgBox(0, "Test", $ValueFromOtherExe)

Now, a hotkey is global, keep that in mind, so if in one script I have:

HotKeySet('{Esc}', 'ExitNow')
Func ExitNow()
    Exit
EndFunc

So if I have both those hotkeys in each script/exe then when I press Esc.. what's going to happen?

Also keep in mind that let's say I have a GuiButton... We'll call it $Button1.

Script/Exe One:

$Button1 = GUICtrlCreateButton("Kill Other Exe", 10, 10, 120, 25)

GUISetState()

While 1
    $imsg = GUIGetMsg()
    Select
        Case $imsg = $Button1
            Send('{Esc}')
    EndSelect
Wend

Now let's say I have the hotkey set up in script/exe two that if I press the Esc button that it exits... What's going to happen above when I press the $Button1 in script/exe one to script/exe two?

I've been up for 28 hours now, if this doesn't make sense, I understand... hope it does though.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I've never tried the $CmdLine[0] approach, maybe someone else can give you an example of that here, but I can show you a brief example of what I do.

Script One... (Do a test one, just to see the examples work... Be sure to change the path to the real paths though :lmao: )

$VariableValueToPass = EnvSet("ThisWillBeOnTheOtherScript", "You will see this exact string in the other scripts MsgBox()")
Run("PathToTheOtherExe" & " " & $VariableValueToPass)

Script 2 (also will be compiled to an .exe)

Global $ValueFromOtherExe = EnvGet("ThisWillBeOnTheOtherScript")
MsgBox(0, "Test", $ValueFromOtherExe)

Now, a hotkey is global, keep that in mind, so if in one script I have:

HotKeySet('{Esc}', 'ExitNow')
Func ExitNow()
    Exit
EndFunc

So if I have both those hotkeys in each script/exe then when I press Esc.. what's going to happen?

Also keep in mind that let's say I have a GuiButton... We'll call it $Button1.

Script/Exe One:

$Button1 = GUICtrlCreateButton("Kill Other Exe", 10, 10, 120, 25)

GUISetState()

While 1
    $imsg = GUIGetMsg()
    Select
        Case $imsg = $Button1
            Send('{Esc}')
    EndSelect
Wend

Now let's say I have the hotkey set up in script/exe two that if I press the Esc button that it exits... What's going to happen above when I press the $Button1 in script/exe one to script/exe two?

I've been up for 28 hours now, if this doesn't make sense, I understand... hope it does though.

This is great, will see if i can get it to work not too! :P thanks!

"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

Is it possible to run a program in hidden mode, where it wont show up on taskbar/tray?. Im not sure i want 2 windows shown for same script if its possible to hide the secondary one (which only will run once the game has been found active).


"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

Put #NoTrayIcon at the top of your script (The non-gui one)


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Put #NoTrayIcon at the top of your script (The non-gui one)

Thanks! ...hehe do you ever sleep?:P


"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

I've been posting asleep for the last few hours, no telling what I've got some of you doing :P


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

I've been posting asleep for the last few hours, no telling what I've got some of you doing :P

Even posting asleep your coding is 100 times (or more) better than mine : " />



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Is there a way to "update" something on a GUI without causing flickering?

Now when my script is updating a listbox (to give the user information what is going on), it flickers crazy :P

I tried add some Sleep() but that caused a delay in reaction from the program...

Maybe there is a better way to give a user live-info without causing flicker (then a listbox)?

The reason it flickers is because of the speed the script is going thru and reposting info in the list box. Ive tried add checkers to make sure if the info has already been shown, dont show it again. The problem was during this my brain got overloaded and it turned out more complex then i thought.


"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

She asked a simple question so I gave him/her a simple answer. Did you expect me to articulate my response in three paragraphs? The answer was simple, "No." No explanation was needed. If and when AutoIt supports multithreading, I am sure it will be announced. Besides, I posted that simply to get the fire started. No one was helping this person, so I figured that if I make a post such as that, people would begin to reply with a reasonable answer.

Edited by treck

Share this post


Link to post
Share on other sites

She asked a simple question so I gave him/her a simple answer. Did you expect me to articulate my response in three paragraphs? The answer was simple, "No." No explanation was needed. If and when AutoIt supports multithreading, I am sure it will be announced. Besides, I posted that simply to get the fire started. No one was helping this person, so I figured that if I make a post such as that, people would begin to reply with a reasonable answer.

Hehe, well theres good there are more helpful ppl to explain why something wont work and try give solutions that might work :P


"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

Well, I can only imagine that you have your GUICtrlSetData inside the loop, the only way to keep it from flickering without using a sleep that I've found is, putting the GUISetData in a conditional statement... (If/Then / Case) that way if something isn't true (or is however your setting it up) it only updates then. Otherwise... a flickering you will go.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Here is a small example script of how you might solve your problem:

#include "Coroutine.au3"
#include <GUIConstants.au3>

HotKeySet("{END}", "_exit")

$GUI = GUICreate("Test GUI")
$hLabel1 = GUICtrlCreateLabel("Old text from main script.", 10, 10)
$hLabel2 = GUICtrlCreateLabel("Button pressed.", 10, 30)
GUICtrlSetState($hLabel2, $GUI_HIDE)
$hButton1 = GUICtrlCreateButton("Test Button", 10, 60)
GUISetState()
$modGUI = _CoCreate('Func modGUI()|For $i = 1 To 10|Sleep(1000);So a human can see the label change|    ControlSetText("Test GUI","","Static1", "New Text: " & $i)|Next|EndFunc')
$modGUI1 = _CoStart($modGUI)

$msg = GUIGetMsg()
While $msg <> $GUI_EVENT_CLOSE
    If $msg == $hButton1 Then
        If GUICtrlGetState($hLabel2) == BitOR($GUI_ENABLE, $GUI_HIDE) Then
            GUICtrlSetState($hLabel2, $GUI_SHOW)
        Else
            GUICtrlSetState($hLabel2, $GUI_HIDE)
        EndIf
    EndIf
    $msg = GUIGetMsg()
    Sleep(10)
WEnd

_CoCleanup()

Func _exit()
    Exit
EndFunc

You can get "Coroutine.au3" from my sig.


[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

Here is a small example script of how you might solve your problem:

#include "Coroutine.au3"
#include <GUIConstants.au3>

HotKeySet("{END}", "_exit")

$GUI = GUICreate("Test GUI")
$hLabel1 = GUICtrlCreateLabel("Old text from main script.", 10, 10)
$hLabel2 = GUICtrlCreateLabel("Button pressed.", 10, 30)
GUICtrlSetState($hLabel2, $GUI_HIDE)
$hButton1 = GUICtrlCreateButton("Test Button", 10, 60)
GUISetState()
$modGUI = _CoCreate('Func modGUI()|For $i = 1 To 10|Sleep(1000);So a human can see the label change|    ControlSetText("Test GUI","","Static1", "New Text: " & $i)|Next|EndFunc')
$modGUI1 = _CoStart($modGUI)

$msg = GUIGetMsg()
While $msg <> $GUI_EVENT_CLOSE
    If $msg == $hButton1 Then
        If GUICtrlGetState($hLabel2) == BitOR($GUI_ENABLE, $GUI_HIDE) Then
            GUICtrlSetState($hLabel2, $GUI_SHOW)
        Else
            GUICtrlSetState($hLabel2, $GUI_HIDE)
        EndIf
    EndIf
    $msg = GUIGetMsg()
    Sleep(10)
WEnd

_CoCleanup()

Func _exit()
    Exit
EndFunc

You can get "Coroutine.au3" from my sig.

WOW... talk about dredging up the past... an almost 3 month old post?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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