AutoHotkey Community

It is currently May 26th, 2012, 6:59 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: May 21st, 2009, 3:29 am 
Offline

Joined: September 9th, 2008, 9:41 pm
Posts: 6
Hi, I have a question about using a script to pause or unpause a second script and vise versa.

Basically, I have two scripts that currently work just fine in tandem.
I am looking for a better way to do the pausing and unpausing of the two scripts that does not involve sending keystrokes.
I could try to combine both scripts with use of timers, however, they are already each quite complex and this way works fine.
I would just like if it didnt have to send keystrokes for the tandem scripts to pause each other.
Script A
Code:
;Script A
Loop{
;Long and Boring highly repetitive task
    ;Blah
    ;Blah
    ;Blah
;Send Keystrokes to unpause Script B.
    Send {Shift Down}
    Sleep 50
    Send {F11 Down}
    Sleep 100
    Send {F11 Up}
    Sleep 50
    Send {Shift Up}
    Sleep 100
;Pause Script A.
    Pause,On
}
+F10::Pause,Off


Script B
Code:
;Script B
Loop{
;Short but complex timer and image search based task
    ;BlahBlahBlah
;Send Keystrokes to unpause Script A.
    Send {Shift Down}
    Sleep 50
    Send {F11 Down}
    Sleep 100
    Send {F11 Up}
    Sleep 50
    Send {Shift Up}
    Sleep 100
;Pause Script B.
    Pause,On
}
+F11::Pause,Off


Anyone have any ideas?
Thanks in advance! :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2009, 11:53 am 
The AHK help ! :arrow: "sending data between scripts"


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2009, 8:53 pm 
Offline

Joined: September 9th, 2008, 9:41 pm
Posts: 6
Thanks for the tip!
I'm still having a bit of trouble though.
So far, I can get Script_B to send a message to Script_A to pause Script_A.
However, once paused, it seems that Script_A will no longer recieve messages and cannot be unpaused by Script_B.
Code:
;Script_A
Loop{
    ;Long and Boring highly repetitive task
        ;Blah
        ;Blah
        ;Blah
    }
OnMessage(0x4a,"Receive_WM_COPYDATA")
Receive_WM_COPYDATA()
    {
    Pause Toggle
    }

Code:
;Script_B
TargetScriptTitle=Script_A.ahk ahk_class AutoHotkey
SetTitleMatchMode 2
DetectHiddenWindows On
Loop{
    SendMessage, 0x4a, 0, &CopyDataStruct,, %TargetScriptTitle% ;To pause Script_A (Works great!)
    ;Short but complex timer and image search based task
        ;BlahBlahBlah
    SendMessage, 0x4a, 0, &CopyDataStruct,, %TargetScriptTitle% ;To unpause Script_A (Will not recieve message)
    ;Sleep some unit of time
    }

The only things I know of that work while a script are paused are hotkeys and hot strings.
Is there anyway to get a script to accept a message while it is paused?
Thanks again!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 23rd, 2009, 4:27 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
Quote:
However, once paused, it seems that Script_A will no longer recieve messages and cannot be unpaused by Script_B.
Here's why:
Quote:
MaxThreads - This integer is normally omitted, in which case the monitor function is limited to one thread at a time.
Source: AutoHotkey Documentation: OnMessage

Here's a better method, which can be used from Script_B.ahk without any extra code in Script_A.ahk:
Code:
DetectHiddenWindows, On
SetTitleMatchMode, 2
PostMessage, 0x111, 65403,,, Script_A.ahk ahk_class AutoHotkey


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 23rd, 2009, 7:21 am 
Offline

Joined: September 9th, 2008, 9:41 pm
Posts: 6
Wow, that works wonderfully. Thank you for the help. 8)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: dra, Exabot [Bot], rbrtryn and 57 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group