Question

good people! I'm struggling with a question here. I have the following script:

#If WinActive("ahk_class Chrome_WidgetWin_0") || WinActive("ahk_class Chrome_WidgetWin_1") || WinActive("ahk_class MozillaWindowClass") || WinActive("ahk_class IEFrame")
 WinWaitActive, my_window_name_here - Opera, , 2
 Sleep 1000
 #NoEnv
 SendMode Input
 SetWorkingDir, %A_ScriptDir%
 #SingleInstance force
 Send some-text
 Send {TAB}
 Send some-text
 Send {TAB}
 Send some-text
 return

It triggers when a certain window in a browser gets active. The problem is, it does it only ONCE. But I need it to trigger EVERY TIME that window/tab gets active. Is that somehow possible?

Was it helpful?

Solution

A quick googling reveals http://www.autohotkey.com/board/topic/85660-run-scripts-when-window-opensbecomes-active/ . Its essense is:

You have to check in a continuous loop:

There is no way to >run< a script when a program opens/is active. The reason is that there is "nobody home" to say 'wake up'.

Instead, you can have a script that is running all the time, and one of its functions is to watch for your target window(s) and then call a subroutine to "do whatever".

The "WinTrigger" script linked to further in the thread uses #Persistent and SetTimer which is essentially the same approach but is neater.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top