[v2_a130] winactivate update TargetError

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Cicin
Posts: 7
Joined: 06 Oct 2019, 23:08

[v2_a130] winactivate update TargetError

Post by Cicin » 06 Apr 2021, 08:44

[Moderator's note: Topic moved from v2 Dev.]

code example as follows:

Code: Select all

diy_hotkey::
{
	If ProcessExist("WindowsTerminal.exe")=0
		run windowsTerminal,env      ;path setted by user
	Else If WinActive("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")
		WinHide("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")
	else
		WinShow("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")       ;works well
		Winactivate("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")      ;fails, TargetError
	return
}
winshow works but winactivate fails and tips TargetError .
Several similar examples just goes failing as above.
I see the changing log "Changed WinActivate to throw TargetError if the window is not found" in a130,
but maybe it's a new bug.
Last edited by Cicin on 07 Apr 2021, 02:51, edited 4 times in total.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [v2_a130] winactivate bug?

Post by swagfag » 06 Apr 2021, 10:27

CASCADIA_HOSTING_WINDOW_CLASS is the new windows10 terminal's class. for me:
  • WinShow() does absolutely nothing(unless the window has been hidden, such as by a prior call to WinHide() or through other means) regardless of the number of open terminals or current A_DetectHiddenWindows settings. but neither does it throw any errors when it obviously fails to show(an already shown) window
  • WinActivate() correctly brings up and activates the terminal window(or the lates created one in case there are multiple) regardless of the current window state(minimized, restored but behind other windows, etc) and A_DetectHiddenWindows settings
considering ur exact window arrangement and details about the script youre running are unknown, i cant reproduce it, so u cant tell whether its a newly introduced ahk bug or a previously-suppressed-but-now-detected, already existing bug in ur script

Cicin
Posts: 7
Joined: 06 Oct 2019, 23:08

Re: [v2_a130] winactivate bug?

Post by Cicin » 06 Apr 2021, 19:21

OK,3x, and I updated the code details, for using hotkey to hide and show app window sush as powershell.
It works well in a129 but fails in a130 , maybe cause of the new "winactivate".
swagfag wrote:
06 Apr 2021, 10:27
CASCADIA_HOSTING_WINDOW_CLASS is the new windows10 terminal's class. for me:
  • WinShow() does absolutely nothing(unless the window has been hidden, such as by a prior call to WinHide() or through other means) regardless of the number of open terminals or current A_DetectHiddenWindows settings. but neither does it throw any errors when it obviously fails to show(an already shown) window
  • WinActivate() correctly brings up and activates the terminal window(or the lates created one in case there are multiple) regardless of the current window state(minimized, restored but behind other windows, etc) and A_DetectHiddenWindows settings
considering ur exact window arrangement and details about the script youre running are unknown, i cant reproduce it, so u cant tell whether its a newly introduced ahk bug or a previously-suppressed-but-now-detected, already existing bug in ur script

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [v2_a130] winactivate bug?

Post by swagfag » 06 Apr 2021, 21:58

swagfag wrote:
06 Apr 2021, 10:27
or a previously-suppressed-but-now-detected, already existing bug in ur script
ur code(with the indentation cleaned up) amounts to this:

Code: Select all

diy_hotkey::
{
	If ProcessExist("WindowsTerminal.exe")=0
		run windowsTerminal,env      ;path setted by user
	Else If WinActive("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")
		WinHide("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")
	else
		WinShow("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")       ;works well

	Winactivate("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")      ;fails, TargetError
}
from which it becomes clear that WinActivate() is called unconditionally, every time. thus, if the WinHide() branch is taken, since i dont see u setting A_DetectHiddenWindows anywhere(presumed default - disabled), WinActivate() fails to find the now hidden window, spitting an error. in the previous a129, this call would have failed silently.

u can ignore the error, suppressing it with a try; or restructure ur logic(perhaps u meant to place these calls in a block { ... } - this isnt python)

Cicin
Posts: 7
Joined: 06 Oct 2019, 23:08

Re: [v2_a130] winactivate bug?

Post by Cicin » 07 Apr 2021, 02:50

3x, so clear, brackets forgotten and error in a129- sliently ignored. Great Great Thanks.
swagfag wrote:
06 Apr 2021, 21:58
swagfag wrote:
06 Apr 2021, 10:27
or a previously-suppressed-but-now-detected, already existing bug in ur script
ur code(with the indentation cleaned up) amounts to this:

Code: Select all

diy_hotkey::
{
	If ProcessExist("WindowsTerminal.exe")=0
		run windowsTerminal,env      ;path setted by user
	Else If WinActive("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")
		WinHide("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")
	else
		WinShow("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")       ;works well

	Winactivate("ahk_class CASCADIA_HOSTING_WINDOW_CLASS")      ;fails, TargetError
}
from which it becomes clear that WinActivate() is called unconditionally, every time. thus, if the WinHide() branch is taken, since i dont see u setting A_DetectHiddenWindows anywhere(presumed default - disabled), WinActivate() fails to find the now hidden window, spitting an error. in the previous a129, this call would have failed silently.

u can ignore the error, suppressing it with a try; or restructure ur logic(perhaps u meant to place these calls in a block { ... } - this isnt python)

Post Reply

Return to “Ask for Help (v2)”