A_ThisVariant
Posted: 07 Feb 2024, 13:48
if the same hotkey key can be triggered by multiple #if conditions, would be nice to have an easy way to know which variant triggered the hotkey
Let's help each other out
https://www.autohotkey.com/boards/
https://www.autohotkey.com/boards/viewtopic.php?f=13&t=125771
to allow you to know which variant triggered the hotkey
Code: Select all
Hotkey, If, MouseIsOverNotepad()
Hotkey, F1, F1_Func(), on
Hotkey, If, FirefoxIsActive()
Hotkey, F1, F1_Func(), on
F1_Func()
{
;currently need to loop through all #if conditions and re-test ourselves to determine which variant has triggered this func
if MouseIsOverNotepad()
msgbox mouseover variant
else if FirefoxIsActive()
msgbox winactive variant
}
Code: Select all
HotIf MouseIsOverNotepad
Hotkey "F1", F1_Func.Bind("Notepad")
HotIf FirefoxIsActive
Hotkey "F1", F1_Func.Bind("Firefox")
F1_Func(ThisVariant) {
if ThisVariant = "Notepad"
msgbox "mouseover variant"
else if ThisVariant = "Firefox"
msgbox "winactive variant"
}
Code: Select all
HotIf MouseIsOverNotepad
Hotkey "F1", F1_Func() ; Says "MouseIsOverNotepad"
HotIf(FirefoxIsActive())
Hotkey "F1", F1_Func() ; Says "FirefoxIsActive()"
HotIf(FirefoxIsActive() && otherThings() || moreFunctions())
Hotkey "F1", F1_Func() ; Says "FirefoxIsActive() && otherThings() || moreFunctions()"
F1_Func() {
MsgBox(A_ThisVariant) ; Where the display is the string of the HotIf
}
Code: Select all
HotIf MouseIsOverNotepad
Code: Select all
HotIf MouseIsOverNotepad.Bind(1)
Code: Select all
f := MouseIsOverNotepad
HotIf f
Code: Select all
HotIf (*) => MouseIsOverNotepad()
Code: Select all
#HotIf FirefoxIsActive() && otherThings()
Code: Select all
#HotIf FirefoxIsActive() and otherThings()
I mean "What value is the variable supposed to return?", not "What is the worth of this feature?"
Only #HotIf has a string (it also has an anonymous function). HotIf only has a function object. A function such as HotIf only knows what parameters it was given, not the source code of the expression which provided the values.
If it returns strings, it must return the appropriate string for the current variant. A variant which was created under a && b cannot be referenced by setting the criteria to a and b. A case such as below would create two separate variants, though one would never execute unless the other was disabled.These are equivalent, but should A_ThisVariant return different strings?
Code: Select all
#HotIf a && b
x::MsgBox 1
#HotIf a and b
x::MsgBox 2
thanks. this should workDescolada wrote: ↑16 Feb 2024, 15:22@guest3456, why not useI modified the example for v2 because v1 isn't getting any new features.Code: Select all
HotIf MouseIsOverNotepad Hotkey "F1", F1_Func.Bind("Notepad") HotIf FirefoxIsActive Hotkey "F1", F1_Func.Bind("Firefox") F1_Func(ThisVariant) { if ThisVariant = "Notepad" msgbox "mouseover variant" else if ThisVariant = "Firefox" msgbox "winactive variant" }
ahh gotcha. not sure what the value of the variable should be, given the difficulties already mentioned. i'm fine using the .Bind method