Jump to content

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

Method to detect active window change?


  • Please log in to reply
6 replies to this topic
jaxelrod
  • Members
  • 12 posts
  • Last active: Mar 26 2012 01:09 AM
  • Joined: 28 Mar 2008
There's no obvious way I've found looking at the AHK API to detect when the active window changes and to act on that information.

What I'd like to do is write an AHK script that when an application is focused, all of the other windows in the window group are also brought to the front.

Thanks!
Jeff
Check out my blog, http://www.tipninja.com where I share tips from optimizing your PC use, to cooking and food storage and household organization to personal happiness.

Frankie
  • Members
  • 2930 posts
  • Last active: Feb 05 2015 02:49 PM
  • Joined: 02 Nov 2008
Look at shell hooks: <!-- m -->http://www.autohotke... ... 323#123323<!-- m -->
aboutscriptappsscripts
Request Video Tutorials Here or View Current Tutorials on YouTube
Any code ⇈ above ⇈ requires AutoHotkey_L to run

None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
You can use ShellHook to detect window activations.
Gui +LastFound 
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,Hwnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
{
 WinGetTitle, title, ahk_id %lParam%
 If (wParam=4) { ;HSHELL_WINDOWACTIVATED
  ToolTip WinActivated`n%Title%
  sleep 1000
  ToolTip
 }
}
Frankie beat me :( :wink:

jaxelrod
  • Members
  • 12 posts
  • Last active: Mar 26 2012 01:09 AM
  • Joined: 28 Mar 2008
Thanks so much to both of you! I'll give it a shot.
Check out my blog, http://www.tipninja.com where I share tips from optimizing your PC use, to cooking and food storage and household organization to personal happiness.

Xymmer
  • Members
  • 2 posts
  • Last active: Apr 19 2012 02:53 PM
  • Joined: 19 Apr 2012
thank you for this, works perfectly.
There's a bug in the DLL (not the script I'm sure) where if Remote Desktop Connection has a full window, the scripts stops detecting thewindow change. If you restore RDC the script continues to detct the window changes.

hotkeyguy
  • Members
  • 84 posts
  • Last active: Jun 03 2016 06:44 PM
  • Joined: 18 Nov 2011

Hello again,

 

I never get a value 4 (HSHELL_WINDOWACTIVATED) from wParam.
OS Windows 7 Professional, 64 Bit SP1. Any hints?

 

 

Many thanks and greetings
hotkeyguy



Elgin
  • Members
  • 79 posts
  • Last active: Dec 18 2015 08:07 PM
  • Joined: 29 Jul 2011

Depending on which window is activated you will either get wParam 4 (HSHELL_WINDOWACTIVATED) or 32772 (0x8004; HSHELL_RUDEAPPACTIVATED). The latter occurs much more frequently but you need to check for both to be safe.