Sign in to follow this  
Followers 0
SergioSchulte

Running two .au3 and I want to pause both with the same key "2"

14 posts in this topic

#1 ·  Posted (edited)

Hello guys!

It is my fisrt post in here and I would really appreciate the help.

I'm newbie and I read that I can not run two Func in one .au3 at same time if one of them are sleep, so then I'm running two script files .au3 and using

HotKeySet("2", "TogglePause")

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('PAUSED',900,640)
    WEnd
    ToolTip("")
EndFunc

on the main.au3, the other.au3 keep running without pause.... What should I do to pause them both?

I tried put this Func Pause on both .au3 files, but only the main.au3 pauses when I press 2 and other.au3 keeps running.

Maybe is there anyway to pause all scripts running without any function? Like any code build in AutoIt3_x64.exe

Edited by SergioSchulte

Share this post


Link to post
Share on other sites



Look at the _IsPressed command in the Help file.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can't code the same hotkey for two scripts running simultaneously. The second script would never receive the hotkey as mentioned in the helpfile.

To toggle the Pause as you have in your function, you have to interrupt the main function. Using _Ispressed we can't interrupt a running function therefore once paused your script would never be unpaused. Therefore we have to use a Keyboard Hook to take care of the Hotkey. 

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

>HotString UDF - Keyboard Hook

Script1

#include <HotString.au3>

HotStringSet("2", "TogglePause")
HotKeySet("3", "TogglePause")

Func TogglePause()
    Static $Paused
    $Paused = Not $Paused
    MsgBox(64, "Info", "Script 1 Paused")
    While $Paused
        Sleep(100)
    WEnd
EndFunc   ;==>Pause

Do
    Sleep(10)
Until 0

Script2

#include <HotString.au3>

HotStringSet("2", "TogglePause")
HotKeySet("3", "TogglePause")

Func TogglePause()
    Static $Paused
    $Paused = Not $Paused
    MsgBox(64, "Info", "Script 2 Paused")
    While $Paused
        Sleep(100)
    WEnd
EndFunc   ;==>Pause

Do
    Sleep(10)
Until 0

Instructions for testing.

  • Run both the script simultaneously
  • Press "3" first, only one MsgBox would be popped
  • Press "2", two MsgBox would be popped

Hence, the method with Keyboard Hook should work with your coding way.

Read interrupting a running at the Wiki.

To elaborate on what TheSaint said, you have to modify the way of your coding to get it working with _Ispressed. Likewise

Script1

#include <Misc.au3>

While 1

    If _IsPressed("32") Then ;if two is pressed then
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0


        ;pause the script.
        MsgBox(64, "Info", "Script 1 paused")
        ;unpause when you again press two
        Do
            Sleep(10)
        Until _IsPressed("32")
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0
    EndIf

WEnd

Script2

#include <Misc.au3>

While 1

    If _IsPressed("32") Then ;if two is pressed then
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0


        ;pause the script.
        MsgBox(64, "Info", "Script 2 paused")
        ;unpause when you again press two
        Do
            Sleep(10)
        Until _IsPressed("32")
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0
    EndIf

WEnd

Thumbs up if helped.

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Depends on how you do it, to my mind.

Interrupt a loop by detecting if a key is pressed, by presenting a MsgBox, script is then paused at that point, and can either do an ExitLoop or ContinueLoop from that point on.

For two scripts, you can either run a third script, that writes to an ini file that both other scripts read, or you can use AdLib functions to do similar or only have one of the scripts present the Msgbox (with joint communication using an ini file, etc) while the other uses another checking loop.

Various possibilities anyway.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

>HotString UDF - Keyboard Hook

Script1

#include <HotString.au3>

HotStringSet("2", "TogglePause")
HotKeySet("3", "TogglePause")

Func TogglePause()
    Static $Paused
    $Paused = Not $Paused
    MsgBox(64, "Info", "Script 1 Paused")
    While $Paused
        Sleep(100)
    WEnd
EndFunc   ;==>Pause

Do
    Sleep(10)
Until 0

Script2

#include <HotString.au3>

HotStringSet("2", "TogglePause")
HotKeySet("3", "TogglePause")

Func TogglePause()
    Static $Paused
    $Paused = Not $Paused
    MsgBox(64, "Info", "Script 2 Paused")
    While $Paused
        Sleep(100)
    WEnd
EndFunc   ;==>Pause

Do
    Sleep(10)
Until 0

Instructions for testing.

  • Run both the script simultaneously
  • Press "3" first, only one MsgBox would be popped
  • Press "2", two MsgBox would be popped

Hence, the method with Keyboard Hook should work with your coding way.

To elaborate on what TheSaint said, you have to modify the way of your coding to get it working with _Ispressed. Likewise

Script1

#include <Misc.au3>

While 1

    If _IsPressed("32") Then ;if two is pressed then
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0


        ;pause the script.
        MsgBox(64, "Info", "Script 1 paused")
        ;unpause when you again press two
        Do
            Sleep(10)
        Until _IsPressed("32")
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0
    EndIf

WEnd

Script2

#include <Misc.au3>

While 1

    If _IsPressed("32") Then ;if two is pressed then
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0


        ;pause the script.
        MsgBox(64, "Info", "Script 2 paused")
        ;unpause when you again press two
        Do
            Sleep(10)
        Until _IsPressed("32")
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0
    EndIf

WEnd

Thumbs up if helped.

Regards :)

 

I'm getting this error with your script: ERROR: can't open include file <HotString.au3>

Let me link mine...

So I have Main.au3 with

Global $Paused

HotKeySet("2", "TogglePause")

HotKeySet("{End}", "Terminate")

_RunAU3("other.au3")

Func _RunAU3($sFilePath, $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0)

    Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"', $sWorkingDir, $iShowFlag, $iOptFlag)

EndFunc

While 1

    Call("DoStuffFromMainau3")

WEnd

Func DoStuffFromMainau3()

     MsgBox(4096,"","Running Main.au3 Function.")

EndFun

Func TogglePause()

    $Paused = NOT $Paused

    While $Paused

        sleep(100)

        ToolTip('PAUSED',900,640)

    WEnd

    ToolTip("")

EndFunc

Func Terminate()

    Exit 0

EndFunc

 

Then I have another file Other.au3 with another simple function

Func DoStuffFromOtherau3()

     MsgBox(4096,"","Running Other.au3 Function.")

EndFun

So, what I'm trying to do is... When I click "2", both Function, from Main.Au3 and Other.au3 must be Paused and if I click "2" again, both functions start running again.

Guys, I'm too newbie, sorry if I'm bodering you guys with this, just do answer me if it is dumb, no need to get mad with :-P

Thank very much!

Edited by SergioSchulte

Share this post


Link to post
Share on other sites

Depends on how you do it, to my mind.

Interrupt a loop by detecting if a key is pressed, by presenting a MsgBox, script is then paused at that point, and can either do an ExitLoop or ContinueLoop from that point on.

For two scripts, you can either run a third script, that writes to an ini file that both other scripts read, or you can use AdLib functions to do similar or only have one of the scripts present the Msgbox (with joint communication using an ini file, etc) while the other uses another checking loop.

Various possibilities anyway.

 

I tried it, it did work....... BUT I have to keep 2 key down, and what I need is click 2, not keep it pressed.

Share this post


Link to post
Share on other sites

Look at the _IsPressed command in the Help file.

This only work if the key is pressed, right?

What I need is a normal press key. Click 2 for Pause, click 2 again to continue.

Share this post


Link to post
Share on other sites

>HotString UDF - Keyboard Hook

Script1

#include <HotString.au3>

HotStringSet("2", "TogglePause")
HotKeySet("3", "TogglePause")

Func TogglePause()
    Static $Paused
    $Paused = Not $Paused
    MsgBox(64, "Info", "Script 1 Paused")
    While $Paused
        Sleep(100)
    WEnd
EndFunc   ;==>Pause

Do
    Sleep(10)
Until 0

Script2

#include <HotString.au3>

HotStringSet("2", "TogglePause")
HotKeySet("3", "TogglePause")

Func TogglePause()
    Static $Paused
    $Paused = Not $Paused
    MsgBox(64, "Info", "Script 2 Paused")
    While $Paused
        Sleep(100)
    WEnd
EndFunc   ;==>Pause

Do
    Sleep(10)
Until 0

Instructions for testing.

  • Run both the script simultaneously
  • Press "3" first, only one MsgBox would be popped
  • Press "2", two MsgBox would be popped

Hence, the method with Keyboard Hook should work with your coding way.

Read interrupting a running at the Wiki.

To elaborate on what TheSaint said, you have to modify the way of your coding to get it working with _Ispressed. Likewise

Script1

#include <Misc.au3>

While 1

    If _IsPressed("32") Then ;if two is pressed then
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0


        ;pause the script.
        MsgBox(64, "Info", "Script 1 paused")
        ;unpause when you again press two
        Do
            Sleep(10)
        Until _IsPressed("32")
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0
    EndIf

WEnd

Script2

#include <Misc.au3>

While 1

    If _IsPressed("32") Then ;if two is pressed then
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0


        ;pause the script.
        MsgBox(64, "Info", "Script 2 paused")
        ;unpause when you again press two
        Do
            Sleep(10)
        Until _IsPressed("32")
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0
    EndIf

WEnd

Thumbs up if helped.

Regards :)

 

PhoenixXL, Thank you very much!

I have tried, this is working very well!

Well, if is not too much to ask... :-)

I just do not know where would I set functions on it, I need at least one function on Script1 and one more on Script2... What if I need "while" on Script1 calling many Functions? All functions should be Paused when I press "2"

Share this post


Link to post
Share on other sites
I just do not know where would I set functions on it

 

With the _IsPressed method call your required functions after the EndIf statement.

I'm getting this error with your script: ERROR: can't open include file <HotString.au3>

I've supplied the link in the original post, download the UDF from over there and place it in your Include directory.

Regards :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Ok, I have done what you said... Still not working.
It is really simple, "2" should be the Pause button, like that Func TogglePause()... While not Pause, keep pressing Left mouse button with Func Pressleft() in Main.au3 and looking for a gray pixel on the screen with Func Gray() in Gray.au3, and if is there one, press Right mouse button.

Edited: Updates... So, what is going on now is it that depends how I press "2", sometimes if I press and hold for 1sec, it does work but sometimes only one func work and other do not, vice versa. It is not synchronized, depend the way I press.

Is there anyway to Pause the AutoIt Appliacation? Like when you mouse over on the icon and click on "Script Paused"? Probably this way would be easier.

 

Main.au3

#include <Misc.au3>

HotKeySet("{End}", "Terminate")

_RunAU3("Gray.au3")

Func _RunAU3($sFilePath, $sWorkingDir = "", $iShowFlag = @SW_SHOW, $iOptFlag = 0)
    Return Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & $sFilePath & '"', $sWorkingDir, $iShowFlag, $iOptFlag)
EndFunc

#include <Misc.au3>

While 1

    If _IsPressed("32") Then ;if two is pressed then
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0


        ;pause the script.
        ;unpause when you again press two
        Do
            Sleep(10)
        Until _IsPressed("32")
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0
    EndIf

    Call("Pressleft")

WEnd

Func Pressleft()
    sleep(1000)
    MouseClick("left")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Gray.au3
 

#include <Misc.au3>

While 1

    If _IsPressed("32") Then ;if two is pressed then
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0


        ;pause the script.
        ;unpause when you again press two
        Do
            Sleep(10)
        Until _IsPressed("32")
        ;wait until two is released
        Do
            Sleep(10)
        Until _IsPressed("32") = 0
    EndIf

    Call("Gray")

WEnd

Func Gray()
    $gra = PixelGetColor(826, 86)
    Switch $gra
        case 0xEC1F1E
            sleep(1500)
            MouseClick("right")
    EndSwitch
EndFunc
Edited by SergioSchulte

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

What are the scripts supposed to do ? And with what application ?

As far what I can see you can merge both the scripts to a single While Loop. Thereafter you can use HotKeySet.

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

What are the scripts supposed to do ? And with what application ?

 

It should run two functions at same time, even if one of them is sleep().

I used to use only one script to do the clicks, but now I want to sleep() one click, but if I do it, the other click will stop... So I must run two Scripts, is that right?

It should run with any application, it is just to check the screen and do mouse left/right clicks on the screen location I want, changing the color and location to click... Could be something way more complex with an specific application, but if I can not do this simples thing, I will not progress with it.

UPDATE: It is working, I press 2 and it does Pause, but when I press 2 to continue again, it does not. Not sure if if it is stuck on Pause and won't leave or what else ;-P

UPDATE2: I really did not read the forum rules, I'm really sorry about that, I did not know that was a problem with "Game Automation"... Well, let me explain, in this case, this application is really dumb... I like to watch TV Series, so I use "always on top" option and navigate at same time (doing clicks), or just watch something on the website in flash, some of them need to refresh click on a button whatever... Since my TV is really big and I watch from way back on sofa, I would have to go to the keyboard to refresh my sites. Kind if there is a button to refresh, click on it, case new link appears, click on it, still need to implement a lot, but like I said, I could use it in the future for something complex that really need two functions running.

Well, sorry about my English, it is not my main language.

UPDATE3: It does pause only, not activating again.

Edited by SergioSchulte

Share this post


Link to post
Share on other sites
I understand what the problem at the moment you are facing with _IsPressed (there is a solution though)
but...

I still suspect you are breaking the Forum Rules (Game Automation). Can you now please tell which application are you automating. Without a specific application automation is useless.

Regards  :)


My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

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