AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Multiple Winwait at once?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
shader



Joined: 29 Oct 2004
Posts: 41

PostPosted: Tue Sep 18, 2007 5:53 pm    Post subject: Multiple Winwait at once? Reply with quote

Hi, I'm looking for a manner to launch determinate actions when determinate windows are active and do it in a wise manner, without going on infinite loops and having minimal processor impact.
I've tried with settimer with somethig like this, but it doesnt work cause one winwait interrupts the other:

Code:
#persistent
settitlematchmode, 2
settimer, fire
settimer, notepad
return

fire:
winwaitactive, Firefox
msgbox, fire
return

notepad:
winwaitactive, Notepad
msgbox, Notepad
return


I know I can have multiple scripts running together but I find there are too many autohotkey processes and it's not very easy to manage that way, with lots of scripts running at once. Also, I find that doing a loop with ifwinactive would be too much running it all the day, isnt it?
Any advice?. Many thanks.
Back to top
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 6223

PostPosted: Tue Sep 18, 2007 6:06 pm    Post subject: Re: Multiple Winwait at once? Reply with quote

Code:
#persistent
settitlematchmode, 2
settimer, fire, -1
settimer, notepad, -1
return

fire:
winwaitactive, Firefox
msgbox, fire
return

notepad:
winwaitactive, Notepad
msgbox, Notepad
return


Should work. Smile

Edit: SetTimer, , -1 runs calls the routines only once.
Back to top
View user's profile Send private message
shader



Joined: 29 Oct 2004
Posts: 41

PostPosted: Tue Sep 18, 2007 7:05 pm    Post subject: Reply with quote

Thanks for your answer Skan!. I've tried your suggestion but it seems to have the same behavior: the script waits first for the notepad window so if I activate the firefox one, it doesnt do nothing.
Seems like the winwaits are stacked in the order they are launched, one above the other, in this particular order.
Back to top
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 6223

PostPosted: Tue Sep 18, 2007 7:20 pm    Post subject: Reply with quote

My code in black means I did not test it .. I should have Sad

The following works:

Code:
Gui +LastFound
hWnd := WinExist()

DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )

Return ;                                                 // End of Auto-Execute Section //

ShellMessage( wParam,lParam ) {
  If ( wParam = 4 ) ;  HSHELL_WINDOWACTIVATED
     {
       WinGetTitle, Title, ahk_id %lParam%

       If InStr( Title, "fire" )
          SetTimer, fire, -1

       If InStr( Title, "notepad" )
          SetTimer, notepad, -1

     }
}


fire:
 msgbox, fire
return

notepad:
 msgbox, Notepad
return


Take a look at this post: How to Hook on to Shell to receive its messages?

Smile
Back to top
View user's profile Send private message
shader



Joined: 29 Oct 2004
Posts: 41

PostPosted: Tue Sep 18, 2007 7:43 pm    Post subject: Reply with quote

Incredible!!! I must play with this a lot, it really open lots of doors. Thanks dude!
Back to top
View user's profile Send private message Send e-mail
SKAN



Joined: 26 Dec 2005
Posts: 6223

PostPosted: Tue Sep 18, 2007 7:45 pm    Post subject: Reply with quote

shader wrote:
it really open lots of doors.


Be aware, this method will work only if Explorer is shell. Smile
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6856
Location: Pacific Northwest, US

PostPosted: Tue Sep 18, 2007 10:20 pm    Post subject: Reply with quote

Skan wrote:
My code in black means I did not test it


I was wondering about that. My solution to the tested/untested is the disclaimer in my sig Wink
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6223

PostPosted: Tue Sep 18, 2007 10:28 pm    Post subject: Reply with quote

I seldom post untested .. and those few fail Sad

Smile
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6856
Location: Pacific Northwest, US

PostPosted: Tue Sep 18, 2007 11:32 pm    Post subject: Reply with quote

searching my name for "code" gives 446 matches (assume around 70% of those threads are me actually posting code), while I only have 77 threads that have "tested" (assume 10% are not tested code)

So I only test 22% of the time
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 6223

PostPosted: Wed Sep 19, 2007 6:50 am    Post subject: Reply with quote

Nice stats Smile
Back to top
View user's profile Send private message
0inprogram



Joined: 06 Dec 2007
Posts: 21
Location: chennai

PostPosted: Thu Dec 20, 2007 2:31 pm    Post subject: Reply with quote

cant we use space in the title field....

for example i used "Google Talk" instead of "Google" in the above script....

but it showed up an error and the script jus couldnt load
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger
breech



Joined: 04 Jul 2005
Posts: 10

PostPosted: Wed Feb 20, 2008 12:51 pm    Post subject: another way Reply with quote

this is easy & works for me:

Start:
gosub thread1
gosub thread2
gosub thread3
gosub thread4
goto Start ; or replace with timer/end whatever

Thread1:
WinWait, Calc,
msgbox, Calc,
return

Thread2:
WinWait, Firefox,
msgbox, Firefox,
return

etc
Back to top
View user's profile Send private message
Oberon



Joined: 18 Feb 2008
Posts: 456

PostPosted: Wed Feb 20, 2008 12:59 pm    Post subject: Reply with quote

engunneer wrote:
My solution to the tested/untested is the disclaimer in my sig
You write code in the reply texbox?! o_O

breech the gosub method is inferior to SetTimer because its single threaded, so you code will only detect firefox when calc is found and dealt with.
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6856
Location: Pacific Northwest, US

PostPosted: Wed Feb 20, 2008 4:49 pm    Post subject: Reply with quote

Oberon wrote:
You write code in the reply texbox?! o_O


If by this, you mean to ask "Do you write code off the top of your head right into the reply on the forum?", then yes. I often do.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
jaco0646



Joined: 07 Oct 2006
Posts: 638
Location: MN, USA

PostPosted: Wed Feb 20, 2008 5:52 pm    Post subject: Reply with quote

engunneer wrote:
Do you write code off the top of your head right into the reply on the forum?

I wish I was that good. Surprised

I associate with SKAN.
SKAN wrote:
I seldom post untested .. and those few fail Sad


Laughing
_________________
http://autohotkey.net/~jaco0646/
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group