Code: Select all
MsgBox % IsLabel("::a") ;1
::a::abc
But in v2 IsLabel only returns 1 if "the specified label exists within the current scope", where label means only labels, *not* hotkeys or hotstrings.
Code: Select all
MsgBox IsLabel("::a") ;0
MsgBox IsLabel("b") ;1
::a::abc
b:
return
edit:
I found the answer at Hotstring#Errors
So we can use this (building on the doc's example)A TargetError is thrown if Replacement is omitted and String is valid but does not match an existing hotstring. This can be utilized to test for the existence of a hotstring.
Code: Select all
IsHotstring(Name) {
Try Hotstring(Name)
Catch TargetError
Return 0
Return 1
}
However the above function only detects hotstrings that have no #HotIf context limitations.
To detect a hotstring in a context we can use
Code: Select all
IsHotstring(Name, Context := "") {
Try HotIf Context ;defaults to turns of context-sensitivity from last call
Try Hotstring(Name)
Catch TargetError
Return 0
Return 1
}
In contrast v1 IsLabel() returns 1 if the hotstring exists in any (at least one) context. Is there some v2 workaround to check if a hotstring exists across all contexts?
edit4:
- Changed from HotIfWinActive(Context) to Try HotIf Context to allow for more contexts and avoid error if parameter Context does not match an existing #HotIf context.
- Changed term 'Scope' to 'Context' because the HotIf documentation talks about context and scope is something else.
- Removed conditional so that Try HotIf Context always runs even if no Context parameter is supplied, in order to then clear the HotIf context set by previous function calls.
- Added note that v1 IsLabel() doesn't detect Hotstring() or Hotkey() created hotstrings/hotkeys.