Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

WinTrigger: Watch [de]activation/[un]existance of windows...


  • Please log in to reply
27 replies to this topic
MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

Yes, that's exactly what my example does! (see the "CUSTOM LABEL SECTION")

What's your point?


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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.


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

Yes, that's exactly what my example does! (see the "CUSTOM LABEL SECTION")

What's your point?

sorry if i wasn't clear. how can i modify your script so that when Calculator is NOT active i also receive a message box alert?



MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
I had hopes this should be pretty straightforward:
 
ProgWinTitle1 = ahk_class Notepad
WinTrigger1 = Exist
The label LabelTriggerOn1 is executed when Notepad exists.
The label LabelTriggerOff1 is executed when Notepad is closed.
 
ProgWinTitle2 = Calculator
WinTrigger2 = Active
The label LabelTriggerOn2 is executed when Calculator is activated.
So, all you have to do is add a LabelTriggerOff2 label, which will be
executed whenever the Calculator window loses focus.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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.


Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012

 

I had hopes this should be pretty straightforward:
 
ProgWinTitle1 = ahk_class Notepad
WinTrigger1 = Exist
The label LabelTriggerOn1 is executed when Notepad exists.
The label LabelTriggerOff1 is executed when Notepad is closed.
 
ProgWinTitle2 = Calculator
WinTrigger2 = Active
The label LabelTriggerOn2 is executed when Calculator is activated.
So, all you have to do is add a LabelTriggerOff2 label, which will be
executed whenever the Calculator window loses focus.

 

sorry, i misunderstood. i was looking at WinTrigger: Active line and associating this Active with the Calculator.



Binocular222
  • Members
  • 99 posts
  • Last active: Jul 25 2014 04:28 AM
  • Joined: 26 Feb 2012

This would be easier to understand:

#notrayicon
#SingleInstance force

MonitoringList=
(
ahk_class Notepad                        | Exist     | DynaRun | Winclose ahk_class Notepad
UniKey 4.0 RC2 ahk_class #32770 | Active   | GoSub     | LabelUnikey
)

Loop, parse, MonitoringList, `n
{
  StringSplit, Condition, A_LoopField, |, %A_Space%%A_Tab%
  if( Win%Condition2%(Condition1) )
  {
    if (Condition3 = "DynaRun")
      DynaRun("#notrayicon `n" Condition4)
    Else if (Condition3 = "Gosub")
    Gosub %Condition4%
 }
}
Return

LabelUnikey:
msgbox, wfe

You will need DynaRun in library:

http://www.autohotke...ss-dynamically/

 

DynaRun: Pass any AHK command to this function and it will be executed in a serarate Autohotkey.exe process

(thus Winclose will not work because no LastFoundWindow. You need to explictly state the WinTitle for Winclose)



Binocular222
  • Members
  • 99 posts
  • Last active: Jul 25 2014 04:28 AM
  • Joined: 26 Feb 2012

You may need to add settimer to above script to constantly monitor.

SheelHook doesn't need settimer, but cannot detect child window (i.e: open/save as dialog box).

It's around the forum, but I still post here to save you a little search:

SetBatchLines, -1
Process, Priority,, High

Gui +LastFound
hWnd := WinExist()

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

ShellMessage( wParam,lParam )
{
  If ( wParam = 1 ) ;  1 means HSHELL_WINDOWCREATED
	{
Settitlematchmode, 2
Ifwinexist, ahk_group OpenMaximized
WinMaximize
Ifwinexist, ahk_group EnterIfExist
Sendinput, {Enter}
Ifwinexist, Add File(s)
Sendinput, {Tab 6}{Enter}
Ifwinexist, Calcute
Winset, AlwaysOnTop, On
Ifwinexist, ahk_class muiWindow
Winset, AlwaysOnTop, On
}
}
Return



Binocular222
  • Members
  • 99 posts
  • Last active: Jul 25 2014 04:28 AM
  • Joined: 26 Feb 2012

Another method is an indefinite Loop of Gosub => winwait

ActionWhenChildWindowCreated:
;Warning: this command loop indefinitely, nothing is processed after this command => Must place this command at the end of script
Winwait, ahk_group ActionWhenChildWindowCreated

ifwinactive, ahk_group ChildwindowEnter
Sendinput {Enter}

ifwinactive, Microsoft Excel ahk_class #32770, This workbook contains links to other data sources.
PostMessage, 0x112, 0xF060    ;0x112 = WM_SYSCOMMAND, 0xF060 = SC_CLOSE

ifwinactive, ahk_group ResizeFileBrowser
Winmove,,,A_ScreenWidth/10,10,A_ScreenWidth/1.3,A_ScreenHeight/1.07

sleep, 2000
Gosub, ActionWhenChildWindowCreated


terrypin
  • Members
  • 174 posts
  • Last active: Mar 15 2017 10:00 AM
  • Joined: 10 Jul 2009
@MasterFocus
 
This looks very promising as a way of doing what I asked about in this thread:
http://www.autohotke...title-is-opened
 
I have it working in the form you demonstrated, namely displaying a message box when the relevant one of 8 file browser dialog windows is opened:

Code removed from this post.
Please see: github.com/MasterFocus
But I'm a novice and haven't grasped how to then run my main script (which is working OK on its own) whenever any of those dialogs is opened. IOW I'm not really clear how to implement your mysub stuff and would appreciate any advice you can offer please.
 
In case it's relevant, here is that main script (which automatically switches the file browser to Detail View, avoiding the use of a hotkey):
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#NoTrayIcon

; Assumes an XP single-pane Explorer folder or a file browser is open.
; Detail View script from noname, 25th August 2013

ControlGet, ctrlid,hwnd,, SysListView321, A
ControlGet,hwnd_child,hwnd,,,ahk_id %ctrlid% 
parent:=DllCall("GetParent","UInt",hwnd_child) 
PostMessage,0x111,0x702c,0,,ahk_id %parent%  ;set listview mode detail
sleep 20
PostMessage, 0x111, 30213,,, ahk_id %parent% ; sort Date modified
sleep 20
PostMessage, 0x111, 30213,,, ahk_id %parent% ; to get sort reversed 
return

--
Terry, East Grinstead, UK

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

My template executes a different label for each window, as you confirmed.

All you have to do is

>> replace my MsgBox with your desired commands, making the necessary changes (possibly using the contents of the variables shown by my MsgBox)

OR

>> create unique actions for each window, like this:

LabelTriggerOn1:
    MsgBox, % "Action 1`nA_ThisLabel:`t" A_ThisLabel "`nProgWinTitle:`t" ProgWinTitle "`nWinTrigger:`t" WinTrigger
Return
LabelTriggerOn2:
    MsgBox, % "Action 2`nA_ThisLabel:`t" A_ThisLabel "`nProgWinTitle:`t" ProgWinTitle "`nWinTrigger:`t" WinTrigger
Return
LabelTriggerOn3:
    MsgBox, % "Action 3`nA_ThisLabel:`t" A_ThisLabel "`nProgWinTitle:`t" ProgWinTitle "`nWinTrigger:`t" WinTrigger
Return
...
...
...

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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.


terrypin
  • Members
  • 174 posts
  • Last active: Mar 15 2017 10:00 AM
  • Joined: 10 Jul 2009

Thanks Antonio, I'll get stuck into that asap.

 

--
Terry, East Grinstead, UK



terrypin
  • Members
  • 174 posts
  • Last active: Mar 15 2017 10:00 AM
  • Joined: 10 Jul 2009

Antonio,

 

That first method worked perfectly, thanks so much!

 

BTW (a very basic question I realise!), instead of pasting the text of my script into yours, is there some way to just enter a single line identifyng my script please?

 

--
Terry, East Grinstead, UK



MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

Depending on what you want (perhaps execute a function), you can use #Include.

Other methods may involve using InputBox (or FileSelectFile(?)) and then using Run/RunWait.

 

Still, WinTrigger itself is a template, so the basic usage is really modifying it to suit your needs.


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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.


Dave197
  • Members
  • 3 posts
  • Last active: Feb 12 2014 11:20 PM
  • Joined: 22 May 2013

Just picking up this thread as I am trying without success to create a script that, on opening an Adobe Acrobat pdf file, sends Control+L to make it fullscreen, rather than have me open it fullscreen (since my keyboard is away from the monitor so it's a fiddle to open something then do fullscreen with the mouse). I tried this:

 

#Persistent
SetTitleMatchMode, 2
ProgWinTitle1 = Adobe Reader
WinTrigger1 = Exist
CheckPeriod = 2000
SetTimer, LabelCheckTrigger, %CheckPeriod%
Return
LabelCheckTrigger:
send ^l
return

 

Unfortunately this has caused two problems. Firstly whenever I open a pdf, withint two seconds it goes to fullscreen, which is just what I want. The problem is, two seconds later it's back to normal view again as Control+L for an Acrobat file in fullscreen takes it back to maximum or whatever last window size was.

 

Secondly a bizarre thing is happening to my browser (either Firefox or IE) after running the script - mouse scrollwheel stops working and any letter I type into anywhere in the browser (e.g. a search box, a message like this, not just the url) jumps straight to the url box and activates whatever the latest webstie beginning with that letter was. No idea why this script should do that but I have to log out and back in again to fix the browser issue - totally random.

 

Would appreciate if someone could advise where I'm going wrong on both counts.