WinWaitActive in SetTimer keeps interfearing with the rest of the script

Get help with using AutoHotkey and its commands and hotkeys
vsub
Posts: 158
Joined: 29 Sep 2015, 03:39

WinWaitActive in SetTimer keeps interfearing with the rest of the script

16 Jun 2019, 11:18

I have 1 scripts that is like all on one(it has many features)but when a certain timer is executed,it keeps making different things from the script not work until I activate the window the WinWaitActive is waiting for

Is there is some way to make that timer thread always interruptible(execute other things...usually hotkeys from #IfWinActive)

That timer is making periodical backups of certain files(every 1 hour)but I want to copy the files only if certain process exist and if it exist,only do the backup if the window is active.
Rohwedder
Posts: 1988
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: WinWaitActive in SetTimer keeps interfearing with the rest of the script

17 Jun 2019, 01:29

Hallo,
if you don't use Critical a timer with WinWaitActive is interruptible.
But why WinWaitActive? Try:

Code: Select all

SetTimer, Backup, 1000
Backup:
Process, Exist, ahk_exe YourProcess.exe
If ErrorLevel And WinActive("Your Window")
{
	;making backup
}
Return
vsub
Posts: 158
Joined: 29 Sep 2015, 03:39

Re: WinWaitActive in SetTimer keeps interfearing with the rest of the script

17 Jun 2019, 09:59

I am not using Critical but almost every hour I notest something is not working until I make that window active

I want to use a WinWaitActive because after that I set another different or the same wait time for the same SetTimer

It's like this.
The program is making backups every hour if it's running(minimized or not)but it is saving those backups in a folder I don't want(I can't change it)and that folder is automatically deleted on windows restart\crash\shutdown.
When the program is minimized for more than 1 hour,there is no point of copying the new backup because the backup will be almost identical to the last one so I am waiting until the windows get active to copy the latest backup

Lets say the program makes one backup and I copy it but then minimize it for the next 5 hours or more...there is no point in copying almost identical files because in the "AHK copy" backup folder,I limit the backups to 10 so instead of having 5 different and 5 almost identical,WinWaitActive allows me to limit the duplicates as mush as possible(the files are not 100% the same size)
just me
Posts: 6366
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: WinWaitActive in SetTimer keeps interfearing with the rest of the script

17 Jun 2019, 11:10

WinWaitActive:
Remarks wrote:While the command is in a waiting state, new threads can be launched via hotkey, custom menu item, or timer.
But you can try:

Code: Select all

While !WinActive("YourWindowCriteria")
   Sleep, 10 ; or 50 / 100 / 500 / ...
A_AhkUser
Posts: 1074
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: WinWaitActive in SetTimer keeps interfearing with the rest of the script

17 Jun 2019, 13:32

vsub wrote:
16 Jun 2019, 11:18
My guess is that your timer is started from the auto-execute section and your hotkeys created thereafter within it using the Hotkey command (rather than being created using double-colon label). If so, it can be expected that before the script may have encountered them and set them, the WinWaitActive command is blocking the execution.

Here's an other option:

Code: Select all

global title := "YourWindowCriteria"

onPopup(hwnd) {
	if (WinExist(title . A_Space . "ahk_id " . hwnd)) {
		; your window activation handling stuff...
		DllCall("DeregisterShellHookWindow", "UInt", A_ScriptHwnd) ; comment this line if the window is likely to be displayed more than one time during the script's lifecycle
	}
}
; =====================================
shellMessage(wParam, lParam) { ; based on https://autohotkey.com/board/topic/80644-how-to-hook-on-to-shell-to-receive-its-messages/
	static _ := ("", DllCall("RegisterShellHookWindow", "UInt", A_ScriptHwnd), OnMessage(DllCall("RegisterWindowMessage", "Str", "SHELLHOOK"), "shellMessage"))
	Critical
	if (wParam = 32772 or wParam = 4) {
		fn := Func("onPopup").bind(lParam)
		SetTimer % fn, -1
	}
}

Return to “Ask For Help”

Who is online

Users browsing this forum: Bad husband, Flipeador, Google [Bot] and 164 guests