| View previous topic :: View next topic |
| Author |
Message |
shader
Joined: 29 Oct 2004 Posts: 41
|
Posted: Tue Sep 18, 2007 5:53 pm Post subject: Multiple Winwait at once? |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Sep 18, 2007 6:06 pm Post subject: Re: Multiple Winwait at once? |
|
|
| 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.
Edit: SetTimer, , -1 runs calls the routines only once. |
|
| Back to top |
|
 |
shader
Joined: 29 Oct 2004 Posts: 41
|
Posted: Tue Sep 18, 2007 7:05 pm Post subject: |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Sep 18, 2007 7:20 pm Post subject: |
|
|
My code in black means I did not test it .. I should have
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?
 |
|
| Back to top |
|
 |
shader
Joined: 29 Oct 2004 Posts: 41
|
Posted: Tue Sep 18, 2007 7:43 pm Post subject: |
|
|
| Incredible!!! I must play with this a lot, it really open lots of doors. Thanks dude! |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Sep 18, 2007 7:45 pm Post subject: |
|
|
| shader wrote: | | it really open lots of doors. |
Be aware, this method will work only if Explorer is shell.  |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Tue Sep 18, 2007 10:20 pm Post subject: |
|
|
| 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  _________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Tue Sep 18, 2007 10:28 pm Post subject: |
|
|
I seldom post untested .. and those few fail
 |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Tue Sep 18, 2007 11:32 pm Post subject: |
|
|
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 |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 6223
|
Posted: Wed Sep 19, 2007 6:50 am Post subject: |
|
|
Nice stats  |
|
| Back to top |
|
 |
0inprogram
Joined: 06 Dec 2007 Posts: 21 Location: chennai
|
Posted: Thu Dec 20, 2007 2:31 pm Post subject: |
|
|
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 |
|
 |
breech
Joined: 04 Jul 2005 Posts: 10
|
Posted: Wed Feb 20, 2008 12:51 pm Post subject: another way |
|
|
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 |
|
 |
Oberon
Joined: 18 Feb 2008 Posts: 456
|
Posted: Wed Feb 20, 2008 12:59 pm Post subject: |
|
|
| 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 |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6856 Location: Pacific Northwest, US
|
Posted: Wed Feb 20, 2008 4:49 pm Post subject: |
|
|
| 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 |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 638 Location: MN, USA
|
Posted: Wed Feb 20, 2008 5:52 pm Post subject: |
|
|
| 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.
I associate with SKAN. | SKAN wrote: | I seldom post untested .. and those few fail |
 _________________ http://autohotkey.net/~jaco0646/ |
|
| Back to top |
|
 |
|