[V2.beta.3] HotIfWinActive: WinTitle fail if Hwnd or GUI object with Hwnd property Topic is solved

Report problems with documented functionality
neogna2
Posts: 590
Joined: 15 Sep 2016, 15:44

[V2.beta.3] HotIfWinActive: WinTitle fail if Hwnd or GUI object with Hwnd property

Post by neogna2 » 07 Dec 2021, 07:17

https://lexikos.github.io/v2/docs/commands/HotIf.htm#IfWin
HotIfWinActive [WinTitle, WinText] ... WinTitle and WinText have the same meaning as for WinActive or WinExist ... See WinTitle for details.
https://lexikos.github.io/v2/docs/misc/WinTitle.htm#ahk_id
Use ahk_id HWND, HWND (that is, without the ahk_id keyword) or ...
Gui and GuiControl objects have a Hwnd property and therefore can be used directly in WinTitle.

Code: Select all

MyGui := Gui()
MyGui.Show("y300 w150 h100")
HotIfWinActive(MyGui.Hwnd)           ;fail despite allowed in doc 
;HotIfWinActive(MyGui)                ;fail despite allowed in doc
;HotIfWinActive("ahk_id " MyGui.Hwnd) ;success
HotKey("LButton", GuiClick)
return

GuiClick(*) {
  if WinExist(MyGui.Hwnd) ;success
    MsgBox(A_ThisHotkey)
}

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

Re: [V2.beta.3] HotIfWinActive: WinTitle fail if Hwnd or GUI object with Hwnd property

Post by swagfag » 07 Dec 2021, 21:56

its because https://github.com/Lexikos/AutoHotkey_L/blob/6012f87b817e8823c48608960c37a77e48ca3e74/source/script2.cpp#L14523 doesnt make use of https://github.com/Lexikos/AutoHotkey_L/blob/6012f87b817e8823c48608960c37a77e48ca3e74/source/script2.cpp#L8986-L9003

if u pass:
  • an Object, its converted into an empty string. if u pass an empty string, the LastFoundWindow is used in the decision
  • a plain hwnd, its converted into a string. so ure looking for a window with a title of "934653745" for example
  • a hwnd with ahk_id, then it works correctly. same as in v1
i dont know what the plan for these -IfWin*** type functions is. the regular ones already got deleted. @lexikos can tell u more

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: [V2.beta.3] HotIfWinActive: WinTitle fail if Hwnd or GUI object with Hwnd property

Post by lexikos » 08 Apr 2022, 22:33

The parameters of HotIfWin are required to be text only. This needs to be clarified in the documentation.

It is not only because the functions are designed to expect only strings, but because the current implementation of window-based hotkey criterion only operates on the WinTitle and WinText strings. These strings are used not only to evaluate the hotkey's applicability, but also to identify the criterion and distinguish hotkey variants.

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: [V2.beta.3] HotIfWinActive: WinTitle fail if Hwnd or GUI object with Hwnd property  Topic is solved

Post by lexikos » 09 Jun 2022, 03:35

The documentation was updated for v2.0-beta.4.
WinTitle, WinText
Type: String
...
WinTitle and WinText have the same meaning as for WinActive or WinExist, but only strings can be used, and they are evaluated according to the default settings for SetTitleMatchMode and DetectHiddenWindows as set by the auto-execute thread. See WinTitle for details.
Source: HotIf - Syntax & Usage | AutoHotkey v2

Post Reply

Return to “Bug Reports”