Jump to content

Using one script to pause another script


Recommended Posts

I've looked in the help file for "pause" and also searched here for the same keyword in the topic title, but haven't come across what I'm looking for.

I've got a macro that I run quite often that uses MAGS' timer functions, and it works very well. The issue I have is that I'm trying to incorporate another timer into it that will read a memory address and execute the function it calls, but this timer doesn't seem to want to work in the main script. I have tested the function alone, outside of my main macro, and it works fine.

So, my thought was just to run this small function as a stand-alone macro and just have it pause the main macro each time it is scheduled to execute. And, after thinking about it more, this would probably be the better way to go, since others I know will be using this with their own modified versions of the main macro.

All of the "pause" topics here seem to have to do with people wanting a pause button or a pause icon in the system try. What I want is for the stand-alone mac to pause the main mac on its own, without any intervention from me.

So, if my mini, stand-alone mac is called "StandAlone" and the main mac is called "MainMac", I'd like to set up "StandAlone" something like:

_TimersInitialize()
_TimerSet ("CheckChatTimer", 120000, "CheckChat")
_TimerStart ("CheckChatTimer")

Func CheckChat()
  Pause ("MainMac.au3")
  .
  .
  .
  Resume ("MainMac.au3")
EndFunc

And StandAlone could be started at any time. It is possible (and very likely) that I'd start it up well after MainMac has been running for quite some time already, and I would probably be in a position where I would not want to completely stop MainMac.

If you guys have any suggestions, or can point me in the direction of a topic that I may have missed that answers this, I'd appreciate it.

Link to comment
Share on other sites

By wild coincidence, I just put together something that might be what you are looking for because the built-in timer and sleep functions don't seem to work on our hyperthreading machines.

_TimeDelayForMS() waits a fixed number of milliseconds, and _TimeDelayUpToMS() waits up to a timeout for a named function (or equation) to return anything but 0.

_TimeDelayForMS(10000)
_TimeDelayUpToMS(10000, "MouseAt00()")

Func _TimeDelayForMS($ms, $showToolTip=1)
    $startTime=API_GetTickCount()
    $endTime = $startTime + $ms
    While API_GetTickCount() < $endTime
        ;ToolTip(@Hour & ':' & @Min & ':' & @Sec & ':' & _MSec())
        If $showToolTip = 1 then ToolTip(API_GetTickCount())
        Sleep(1)
    WEnd
EndFunc

Func _TimeDelayUpToMS($ms, $exitCondition, $showToolTip=1)
    $startTime=API_GetTickCount()
    $endTime = $startTime + $ms
    While API_GetTickCount() < $endTime and Execute($exitCondition)=0
        If $showToolTip = 1 then ToolTip(API_GetTickCount())
        Sleep(1)
    WEnd
EndFunc

Func MouseAt00() ; As Boolean
    If MouseGetPos(0) + MouseGetPos(1) = 0 then Return 1
    Return 0
EndFunc

Func API_GetTickCount()
    $t=DllCall("kernel32.dll", "int", "GetTickCount")
    Return $t[0]
EndFunc

If you really want to be able to control one script from another running as a seperate process, I'm quite fond of passing commands across the registry, roughly:

Script 1:

RegWrite($targ, $val, $type, $content)

While RegRead($targ, $val) = $content

Sleep(1)

WEnd

Script 2:

While RegRead($targ, $val)=""

Sleep(1)

WEnd

MyFunction()

RegWrite($targ, $val, $type, "OK")

Edited by sohfeyr
Link to comment
Share on other sites

You need to comunicate state between your scripts or you ahve to figure out how to suspend the main thread of the process.

Link to comment
Share on other sites

@ Uten: I think suspending is getting in way over my head at this point in my AutoIt use. And communicating states between scripts...all the examples in the help file seem to be dealing with the currently running script, unless I'm missing something, which I probably am.

@ sohfeyr: When I originally started working on my script a few months ago, I must not have done a good search on timers. I don't remember seeing that there were already timer functions in AutoIt. Maybe MAGS' functions are actually too complicated in the way that they work for what I'm trying to accomplish. I'll give the built-in timer functions a try and see if that gets me around the issue I'm having. But your _TimeDelayForMS function seems like it might be more reliable yet. It looks to me like you have it working off the actual PC's clock rather than doing a basic countdown (if I'm not mistaken), and that would lead to a more consistent execution of a timed function since online lag would hopefully not play much of a part.

I'd still like to get these working as two separate scripts and was really hoping AutoIt had a simple Pause/Resume function for handling another script.

Thanks to both of you for your input.

Link to comment
Share on other sites

But your _TimeDelayForMS function seems like it might be more reliable yet. It looks to me like you have it working off the actual PC's clock rather than doing a basic countdown (if I'm not mistaken), and that would lead to a more consistent execution of a timed function since online lag would hopefully not play much of a part.

You're welcome, and you're right - that's exactly what it does. If you decide to go ahead with Sleep(), TimerInit() and TimerDiff(), be forewarned that they don't seem to work (for me) on hyperthreading or multiprocessor machines.

I'd still like to get these working as two separate scripts and was really hoping AutoIt had a simple Pause/Resume function for handling another script.

Take a look in the help file at the example for HotKeySet. It is literally (get this) "TogglePause". If you're running two scripts simultaneously in seperate processes, then you should be able to use HotKeySet in one script and Send in another. See my response to a similar question here

(http://www.autoitscript.com/forum/index.php?s=&showtopic=31669&view=findpost&p=227346)

Link to comment
Share on other sites

Well, I switched all the timed functions over from MAGS' functions to the built-in ones in AutoIt. So far, from the minimal testing I've done with them, they seem to be doing the job nicely. I've set up my main timers as the TimerInit and TimerDiff options, then set up my function that I want to really take control as an AdlibEnable. It seems to be working out OK that way.

I don't do hyperthreading (at least I don't think so) and I don't have a multiprocessor machine, so AutoIt's functions may do just fine for me.

And thanks for sending me in the directon of TogglePause. I'll take a look at it when I've got a little more time. As I have the script now, it works fine for me, but others would not be using the same script as I am, so I'd still like to look into two separate ones.

Thanks again for your (and Uten's) help.

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