How to know when any window is activated
-
- Posts: 40
- Joined: 12 Jun 2021, 15:28
How to know when any window is activated
So basically, this is for a project im making, and the last piece of it, is to detect when any window is activated, I've searched and found people using ShellHook but it's not working how I want it to, it only works if a new window is open, not when you change from one window to another, perhaps this has to do with my windows version (Windows 10), im not entirely sure, thing is, lets say i use shellhook for it, when I open a new window that doesn't exist yet, it works, but when I open a window that does exist but hasn't been activated, it doesn't work, I want this to detect when a window is activated not when a new one is made
Re: How to know when any window is activated
Did you try to use WinActivate (activates the window you want) or WinGetActiveTitle (you cac check which window is now active) functions? Also WinWaitActive / WinWaitNotActive may help.
I used all of the above (mosty first and third one) and they all worked fine for me.
I used all of the above (mosty first and third one) and they all worked fine for me.
-
- Posts: 29
- Joined: 24 Jun 2020, 16:42
Re: How to know when any window is activated
This can be done fairly easily with a Settimer, this for example calls the Notify function every time the activeWin variable changes:
Code: Select all
#Persistent
activeWin := ""
settimer, windowWatch, 10
return
windowWatch:
if (activeWin != WinActive("A")) {
activeWin := WinActive("A")
Notify(activeWin)
}
return
Notify(hwnd) {
static title
WinGetTitle, title, ahk_id %hwnd%
settimer, tooltipoff, -2000
settimer, tooltip, 100
return
tooltip:
Tooltip, % "Window """ title """ activated"
return
tooltipoff:
settimer, tooltip, off
tooltip
return
}
-
- Posts: 40
- Joined: 12 Jun 2021, 15:28
Re: How to know when any window is activated
thank you so much, I hadn't thought of that for some reason, I have this because I just want it to be activated when the mouse is clickedevilmanimani wrote: ↑14 Oct 2021, 18:00This can be done fairly easily with a Settimer, this for example calls the Notify function every time the activeWin variable changes:
Code: Select all
#Persistent activeWin := "" settimer, windowWatch, 10 return windowWatch: if (activeWin != WinActive("A")) { activeWin := WinActive("A") Notify(activeWin) } return Notify(hwnd) { static title WinGetTitle, title, ahk_id %hwnd% settimer, tooltipoff, -2000 settimer, tooltip, 100 return tooltip: Tooltip, % "Window """ title """ activated" return tooltipoff: settimer, tooltip, off tooltip return }
Code: Select all
#Persistent
activeWin := ""
return
~LButton::
Sleep, 200
if (activeWin != WinActive("A")) {
activeWin := WinActive("A")
Notify(activeWin)
}
Notify(win) {
ToolTip, %win%
}
-
- Posts: 40
- Joined: 12 Jun 2021, 15:28
Re: How to know when any window is activated
this isn't exactly what I wanted to achieve, because if I want it to be with any window, and not just thaI, the window that is active will be compared against a list of windows and if its one of those windows, then it'll hide that window, keep an eye out for "WinLock" dropping today on the Scripts and Functions forummauritius wrote: ↑14 Oct 2021, 17:45Did you try to use WinActivate (activates the window you want) or WinGetActiveTitle (you cac check which window is now active) functions? Also WinWaitActive / WinWaitNotActive may help.
I used all of the above (mosty first and third one) and they all worked fine for me.
Re: How to know when any window is activated
When using ShellHook, watch for wParam to be either 4 or 32772
Code: Select all
If(wParam = 4 OR wParam = 32772) ;WINDOWACTIVATED
{
; Check Window / Do Stuff
}
Who is online
Users browsing this forum: MSN [Bot], NinjoOnline and 205 guests