Calling function from function with parameter
Posted: 14 Feb 2020, 18:14
Hello,
The F1 and F2 part works flawlessly:
Now I'm trying to pass parameters, but it does not work.
How to write the F3 part so that the functions get called with parameters?
My main aim is to avoid plenty of code lines like done in F1, because I use a lot of short/long key presses.
Having such a Short_Long function seems to be very handy!
Thanks for any help and best regards!
The F1 and F2 part works flawlessly:
Code: Select all
F1::
KeyWait, F1, T0.2 ; Check if the key has been held down for less than 200 ms
if ErrorLevel = 1 ; Script 2 - Long press
{
Function_2()
}
else ; Script 1 - Short press
{
Function_1()
}
return
F2::
Short_Long_Function(func("Function_1"), func("Function_2"), A_ThisHotkey)
return
Function_1()
{
MsgBox, short press
}
Function_2()
{
MsgBox, long press
}
Short_Long_Function(param1, param2, key)
{
KeyWait, %key%, T0.2 ; Check if the key has been held down for less than 200 ms
if ErrorLevel = 1 ; Script 2 - Long press
{
param2.(myObject)
}
else ; Script 1 - Short press
{
param1.(myObject)
}
}
How to write the F3 part so that the functions get called with parameters?
Code: Select all
F3::
;Short_Long_Function(func("Function_3"), func("Function_4"), A_ThisHotkey) ; Works but without any parameter (Bug?)
;Short_Long_Function(func("Function_3(hello)"), func("Function_4(hello)"), A_ThisHotkey) ; Nothing happens when pressing F3
;Short_Long_Function(func("Function_3("hello")"), func("Function_4("hello")"), A_ThisHotkey) ; It says "Illegal character"
;Short_Long_Function(func("Function_3"(hello)), func("Function_4"(hello)), A_ThisHotkey) ; Works, but no parameter!
;Short_Long_Function(Function_3("hello"), Function_4("hello"), A_ThisHotkey) ; Both functions get called with parameter but short/long does not work
return
Function_3(text)
{
MsgBox, short press %text%
}
Function_4(text)
{
MsgBox, long press %text%
}
Short_Long_Function(param1, param2, key)
{
KeyWait, %key%, T0.2 ; Check if the key has been held down for less than 200 ms
if ErrorLevel = 1 ; Script 2 - Long press
{
param2.(myObject)
}
else ; Script 1 - Short press
{
param1.(myObject)
}
}
Having such a Short_Long function seems to be very handy!
Thanks for any help and best regards!