
how to detect a window is opened?
Started by
A117
, Jun 14 2012 08:46 AM
15 replies to this topic
I would like to do sth. whenever a window is opened. How to write this code please? IfWinActive or WinWait did not work at all.
#1
-
Posted 14 June 2012 - 08:46 AM

#2
-
Posted 14 June 2012 - 09:27 AM

Loop { sleep 500 WinGetActiveTitle, Title If Title = [color=#FF0000]Window Name[/color] break } [color=#00BF00]**Code you want when window is active**[/color]If your right with having a loop
#3
-
Posted 14 June 2012 - 09:28 AM

Sjc1000 - Insert inspirational quote here!
PLEASE find me on the IRC if you have questions. I'm never on the forum anymore.
first, when I said "a window", I meant "any window". So when I used IfWinActive, I would like it to have no parameters.
second, it seems I have to use the Loop, which proved there is no way to simply Detect when a window is opened. All actions so far I know are triggered by Keys. So I still do not know how to trigger the Loop function in ahk file. If I write IfWinExist, ... {... } or Loop {...}, nothing happens. :?:
second, it seems I have to use the Loop, which proved there is no way to simply Detect when a window is opened. All actions so far I know are triggered by Keys. So I still do not know how to trigger the Loop function in ahk file. If I write IfWinExist, ... {... } or Loop {...}, nothing happens. :?:
#4
-
Posted 15 June 2012 - 01:21 AM

you can combine settimer with winget, list and then check the list for new items
something like:
i alsmot made it have a msgbox, but that would add a new window and act recursively!
something like:
;this section runs automatically at startup settimer, checkForNewWindow, 100 ;every 100ms, run the label return checkForNewWindow: ;the label WinGet, id, list,,, Program Manager ;list of windows (exclude the desktop) if id > lastid { Tooltip, %id% windows! SetTimer, ClearTooltip, -2000 } lastid := id ;always keep up to date Return ClearTooltip: Tooltip Return
i alsmot made it have a msgbox, but that would add a new window and act recursively!
#5
-
Posted 15 June 2012 - 01:29 AM

I changed it as above. nothing happened.you can combine settimer with winget, list and then check the list for new items
something like:;this section runs automatically at startup settimer, checkForNewWindow, 100 ;every 100ms, run the label return checkForNewWindow: ;the label WinGet, id, list,,, Program Manager ;list of windows (exclude the desktop) if id > lastid { WinMaximize } lastid := id ;always keep up to date Return
i alsmot made it have a msgbox, but that would add a new window and act recursively!
My workaround below does not work either.
settimer, checkForNewWindow, 1000 ;every 1s, run the label ;return checkForNewWindow: ;the label WinWait,,,,Program Manager ;WinGet, id, list,,, Program Manager ;list of windows (exclude the desktop) ;if id > lastid ;{ WinMaximize ;} Return
#6
-
Posted 15 June 2012 - 02:38 AM

it seems engunneer's script needs #persistent
but as he said, you have to combine with the method above. heres the example that will trigger whenever a new notepad window is opened:
but as he said, you have to combine with the method above. heres the example that will trigger whenever a new notepad window is opened:
#persistent ;this section runs automatically at startup settimer, checkForNewWindow, 100 ;every 100ms, run the label return checkForNewWindow: ;the label WinGet, id, list,,, Program Manager ;list of windows (exclude the desktop) if (id > lastid) { WinGetActiveTitle, Title If InStr(Title, "Notepad") { msgbox, new notepad window opened } } lastid := id ;always keep up to date Return
#7
-
Posted 15 June 2012 - 05:05 AM

settimer just seems not working at all for me. Windows 8it seems engunneer's script needs #persistent
but as he said, you have to combine with the method above. heres the example that will trigger whenever a new notepad window is opened:#persistent ;this section runs automatically at startup settimer, checkForNewWindow, 100 ;every 100ms, run the label return checkForNewWindow: ;the label WinGet, id, list,,, Program Manager ;list of windows (exclude the desktop) if (id > lastid) { WinGetActiveTitle, Title If InStr(Title, "Notepad") { msgbox, new notepad window opened } } lastid := id ;always keep up to date Return
#8
-
Posted 15 June 2012 - 07:01 AM

here is simple settimer test
does this do anything? is there icon for running script?
SetTimer, popup, 3000 msgbox, timer started! return popup: Msgbox Pop! Return Esc::ExitApp
does this do anything? is there icon for running script?
#9
-
Posted 15 June 2012 - 10:49 AM

actually I'm using the current AutoHotkey_L on win 8. the simple test does not work for me
begging part of my ahk
begging part of my ahk
#s::Run "c:\WINDOWS\system32\sndvol32.exe" ;#persistent SetTimer,checkForNewWindow,1000 msgbox, timer started! return checkForNewWindow: msgbox,new notepad window opened Return #PgUp::WinMaximize,A
#10
-
Posted 16 June 2012 - 02:24 AM

Move your #s hot key to the end?
#11
-
Posted 16 June 2012 - 07:36 PM

yes. why? there should be some place telling me settimer must be the first in the script. Or did I just miss it?Move your #s hot key to the end?
Thank you all very much.
#12
-
Posted 18 June 2012 - 05:56 AM

May be useful: [How to] Hook on to Shell to receive its messages?
#13
-
Posted 18 June 2012 - 06:06 AM

actually I'm using the current AutoHotkey_L on win 8. the simple test does not work for me
begging part of my ahk#s::Run "c:\WINDOWS\system32\sndvol32.exe" ;#persistent SetTimer,checkForNewWindow,1000 msgbox, timer started! return checkForNewWindow: msgbox,new notepad window opened Return #PgUp::WinMaximize,A
put the 'simple test' in its OWN script and run it to test this first and let us know
do not put it on top at the beginning of your script because its likely that your script is buggy.
#14
-
Posted 18 June 2012 - 02:29 PM

#Persistent DllCall("RegisterShellHookWindow", "UInt", A_ScriptHWND) OnMessage(DllCall("RegisterWindowMessage", "Str","SHELLHOOK"), "ShellMessage" ) Return ShellMessage(wParam, lParam) { global createdWindowTitle If wParam = 1 WinGetTitle, createdWindowTitle, ahk_id %lParam% SetTimer, ToolTip, -10 } ToolTip: ToolTip, %createdWindowTitle% return
#15
-
Posted 26 June 2012 - 04:26 AM
