Page 1 of 1
A_ThisVariant
Posted: 07 Feb 2024, 13:48
by guest3456
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
Re: A_ThisVariant
Posted: 15 Feb 2024, 23:17
by lexikos
What value is it supposed to have?
Re: A_ThisVariant
Posted: 16 Feb 2024, 09:32
by guest3456
lexikos wrote: ↑15 Feb 2024, 23:17
What value is it supposed to have?
to allow you to know which variant triggered the hotkey
pseudocode example
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
}
Re: A_ThisVariant
Posted: 16 Feb 2024, 15:22
by Descolada
@guest3456, why not use
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"
}
I modified the example for v2 because v1 isn't getting any new features.
Re: A_ThisVariant
Posted: 26 Feb 2024, 07:11
by WarlordAkamu67
There are a few ways to figure out which variant was pressed as with any code stuffs. The HotIf line as a string is one suggestion for the value, if the variable is made.
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
}
Re: A_ThisVariant
Posted: 29 Feb 2024, 02:26
by Descolada
@WarlordAkamu67
Suppose
A_ThisVariant returned the string of the HotIf function call argument.
This case is simple, as A_ThisVariant would be the string
"MouseIsOverNotepad"
However, we can bind arguments to functions:
What should the string be now?
"MouseIsOverNotepad.Bind(1)" or
"MouseIsOverNotepad(1)" or ignore the argument and return
"MouseIsOverNotepad"?
We can also assign functions to variables:
Is
A_ThisVariant now
"MouseIsOverNotepad" or
"f"?
Okay, suppose we said that only the *actual* function name should be returned ("MouseIsOverNotepad", not "f"). What should we do in the case of anonymous functions?
Would
A_ThisVariant be
"" or
"(*) => MouseIsOverNotepad()"?
Then we have the case of #HotIf with multiple conditions, eg
Code: Select all
#HotIf FirefoxIsActive() && otherThings()
but suppose that in another part of my code I used
Code: Select all
#HotIf FirefoxIsActive() and otherThings()
These are equivalent, but should
A_ThisVariant return different strings?
As you see this would get complex and convoluted. Just use BoundFuncs as I showed in my example...
Re: A_ThisVariant
Posted: 29 Feb 2024, 19:26
by lexikos
guest3456 wrote: ↑16 Feb 2024, 09:32
lexikos wrote: ↑15 Feb 2024, 23:17
What value is it supposed to have?
to allow you to know which variant triggered the hotkey
I mean "What value is
the variable supposed to
return?", not "What is the worth of this feature?"
For v1, which I will not be adding features to anyway, criteria is a combination of
multiple parameters.
Descolada wrote: ↑29 Feb 2024, 02:26
Suppose
A_ThisVariant returned the string of the HotIf function call argument.
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.
These are equivalent, but should A_ThisVariant return different strings?
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.
Code: Select all
#HotIf a && b
x::MsgBox 1
#HotIf a and b
x::MsgBox 2
The same would apply to expressions which differ only by case or spacing, even if they have the same result.
Re: A_ThisVariant
Posted: 01 Mar 2024, 06:21
by WarlordAkamu67
I kind of pictured it in my head like trimming the error window code, so whatever that is displayed there. So I guess it would "MouseIsOverNotepad.Bind(1)" and "f"? I don't have any great examples of a use case, but that is what I think of for a potential value, if assigned.
- variant.png (36.95 KiB) Viewed 486 times
Re: A_ThisVariant
Posted: 02 Mar 2024, 20:13
by lexikos
#HotIf is a directive, and as such its parameter is literal source code. The directive creates an anonymous function and sets it as the current hotkey criterion. Since the script has no way to refer to this function directly, it also stores the expression source code for use with the HotIf function and to merge exact duplicates. #HotIf is allowed only in global scope, so two lines with an exactly identical expression would behave the same even if they weren't implicitly merged.
The HotIf function takes a function object. A unique function object may not directly correspond to literal source code, and even if it did, the same snippet of source code can have different interpretations depending on scope. Unlike #HotIf, HotIf can be used in local scope.
More importantly, functions receive only the values of their parameters. Attempting to self-introspect to determine the source code snippet corresponding to the parameter would be slow and error-prone. Error dialogs only show the line that called the function. A line can contain multiple calls to HotIf. The same source code can correspond to many different unique function objects, even if there's only one call to HotIf in the entire script.
Re: A_ThisVariant
Posted: 03 Mar 2024, 22:12
by guest3456
Descolada wrote: ↑16 Feb 2024, 15:22
@guest3456, why not use
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"
}
I modified the example for v2 because v1 isn't getting any new features.
thanks. this should work
lexikos wrote: ↑29 Feb 2024, 19:26
I mean "What value is
the variable supposed to
return?", not "What is the worth of this feature?"
ahh gotcha. not sure what the value of the variable should be, given the difficulties already mentioned. i'm fine using the .Bind method