WinTrigger: Watch [de]activation/[un]existance of windows...
This old forum will be archived ( see https://autohotkey.c...s-decommission/ ).
For my up-to-date code and information, check the following links:
http://git.io/master | https://github.com/MasterFocus | http://masterfocus.ahk4.net/ | https://sites.google...masterfocusahk/
####################################################################################
My template got very popular, so it
definitely deservers its own thread.
This template can be used to watch for windows or
programs and act upon their [de]activation or [un]existance.
Template:
WinTrigger
Description:
Act upon (de)activation/(un)existance of programs/windows
Links:
GitHub (check the AutoHotkey repository)
Related scripts:
• WinWait framework by berban - http://www.autohotke...php?f=2&t=92017
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org
Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.
I'm running Windows7 (64bit).
Other AHK scripts work fine.
I copied the code as is from the script window above.
I run the script and nothing happens when I create or activate a Notepad or Calculator window.
The only change I made was to the custom label section:
; ------ ------ CUSTOM LABEL SECTION ------ ------ LabelTriggerOn1: MSgBox "One On" LabelTriggerOff1: MSgBox "One Off" LabelTriggerOn2: MsgBox % "A_ThisLabel:`t" A_ThisLabel "`nProgWinTitle:`t" ProgWinTitle "`nWinTrigger:`t" WinTrigger Returnto make sure that Notepad did "something".
Thoughts?
Return
for each separate label.There was no need to change anything: all 3 labels would execute the same detailed MsgBox, but with a different message each.
I've just copied my exact code and run it. Works as expected here (AHK Basic + Win7 x64).
I don't see any reason for it not to show the MsgBox properly.
The Calculator example would not work if the window title is different (another language, perhaps). However, the Notepad test should work just fine.
Try using
SetTitleMatchMode, 2
on the top of the script and don't use ahk_class
. Let me know if it works.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org
Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.
I was running 1.0.47.06
I downloaded and installed the latest version and the script works perfectly now.
Thanks for your patience!
Thanks
Ross
Code removed from this post. Please see: github.com/MasterFocusI want to confirm when I initially bring focus to Outlook.
This works fine.
BUT, if I send an email and the focus returns to Outlook it is prompting again - any thoughts on how I can identify the difference?
Thanks In Advance
Ross
It is indeed a different approach. As RossGoodman noted, WinTrigger offers a timer as a simple solution.
More sofisticated and/or time-critical requests may have better luck with other methods.
@RossGoodman: Indeed, adding a hotkey like
Pause::Pause
at the bottom of the script should be enough in your case.I'm glad you liked my template so much you even blogged about it!
I think no one will use it for commercial purposes anyway, but I guess it's better to state that the code is licensed under AGPL v3.0, just in case. :wink:
And here's a quick guide for those (like me) who think that reading licenses is boring. :mrgreen:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org
Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.
Is it possible to script a thing like
LabelTriggerOn1: SetTimer, LabelCheckTrigger, Off ... LabelTriggerOff1: SetTimer, LabelCheckTrigger, On ...
To desactive the check of the window when it's opened
and reactivate the timer at the close of the window?
The "only" way to know if you opened or closed a window is with a timed subroutine.
In that case, it's the purpose of LabelCheckTrigger.
That's actually the only timed subroutine being constantly executed by my script.
If you disable that, there's no way to tell what's going on.
But why would you do that? It doesn't consume a significant amount of CPU or memory at all.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org
Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.
The "only" way to know if you opened or closed a window is with a timed subroutine.
In that case, it's the purpose of LabelCheckTrigger.
That's actually the only timed subroutine being constantly executed by my script.
If you disable that, there's no way to tell what's going on.
But why would you do that? It doesn't consume a significant amount of CPU or memory at all.
In fact, I haven't realized that the closing was linked to the timer. But yeah, it was a bad idea.
in my case, msgbox appears in both cases when Notepad exists or NOT exists. however, in the case of Calculator, msgbox appears only when Calculator is Active. when NOT active, unlike Notepad, msgbox does NOT appear. I also tried with SetTitleMatchMode, 2.