Hook for window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Archimede
Posts: 540
Joined: 25 Nov 2021, 09:49
Location: Switzerland / Italy

Hook for window

07 May 2024, 17:47

Hallo.
Is it possible to set an hook for
Window generation
Window move
That set an asynchronous function call when a new Window is generate or an existing Window is moving.
I know there is winwait but it is not asynchronous, is stop execution waiting for a new Window. I need no stop execution, but an automatic function call when a new Window is generated or an existing Window is moving.
I need a function like existing Input Hook for keyboard, but for Window.
Tank you very much.
Rohwedder
Posts: 7710
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Hook for window

08 May 2024, 02:51

Hallo,
try:

Code: Select all

DllCall("RegisterShellHookWindow", "UInt", A_ScriptHwnd)
OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "act")
Return
act(wParam, lParam)
{
    If (wParam = WINDOWCREATED := 1)
		SoundBeep
}
but when "an existing Window is moving"
could be a problem for a WinHook.
viewtopic.php?style=19&t=24473
peter_ahk
Posts: 120
Joined: 13 Feb 2024, 14:49

Re: Hook for window

08 May 2024, 03:01

what are you trying to achieve? if i had to gues you want some sort of winmove that sets a window to position or size whenever it is active?

if so you could add all those windows to a group and then have a winwaitactive inside a loop for that group and then have some winmove code behind that for my fl studio setup i have something simular that sets all my windows where i want them and keeps them there no matter what. and a few are only being resized as they do not remember their size. then i have another script that waits for fl studio to close so it can close that script and then itself and that bypasses the winwait in one script that would keep it on pause until that window closes

my windows have nothing to do with your setup ofc but just to show you what i mean: in the startup section i have this:

Code: Select all

GroupAdd, MoveResizeWindows , ahk_class TPluginForm , Bloom Drum Breaks
GroupAdd, MoveResizeWindows , ahk_class TPluginForm , Bloom Bass Impulse
GroupAdd, MoveResizeWindows , ahk_class TMIDIInputForm , Remote control settings
GroupAdd, MoveResizeWindows , ahk_class TFXForm , Mixer
GroupAdd, MoveResizeWindows , ahk_class TPluginForm , Mute & Solo Panel
GroupAdd, MoveResizeWindows , ahk_class TPluginForm , Control Surface
GroupAdd, MoveResizeWindows , ahk_class TPluginForm , Correlometer
GroupAdd, MoveResizeWindows , ahk_class TPluginForm , Multimeter
GroupAdd, MoveResizeWindows , ahk_class TPluginForm , Tuner
GroupAdd, MoveResizeWindows , ahk_class TPluginForm , VPS Scope CM edition
and then my loop looks like this:

Code: Select all

Loop{
      WinWaitActive, ahk_group MoveResizeWindows
      WinMove, ahk_class TPluginForm , Bloom Drum Breaks  ,  ,  , 1345 , 918
      WinMove, ahk_class TPluginForm , Bloom Bass Impulse ,  ,  , 1345 , 918
      WinMove, ahk_class TMIDIInputForm , Remote control settings , 1921 , 129 ,  ,
      WinMove, ahk_class TPluginForm , VPS Scope CM edition , 3106 , 574 , 1516 , 857
      WinMove, ahk_class TPluginForm , Correlometer , 1921 , 505 , 737 , 535
      WinMove, ahk_class TPluginForm , Mute & Solo Panel , 2304 , 0 , 322 , 448
      WinMove, ahk_class TPluginForm , Control Surface, 2304 , 448 , 322 , 299
      WinMove, ahk_class TFXForm , Mixer , 2136 , 0 , 1721 , 624
      WinMove, ahk_class TPluginForm , Multimeter , 2967 , 748 , 720 , 502
      WinMove, ahk_class TPluginForm , Tuner , 3745 , 642 , 472 , 610
    }
the first 2 are only being resized whenever active and the rest is fixed to a position

then in another script i have a winwaitclose that deals with closing this script and also itself

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chrysalis and 93 guests