AutoHotKey how to pass/evaluate parameters to functions

autohotkeyparameters

I'm having trouble understanding how parameters are accessed in AutoHotKey functions.

For example, I set myVar variable with the InputBox, then pass it to a function. How do I evaluate the arg in the TestFunction?

#t::
    inputbox myVar, What is your variable?
    myNewVar := TestFunction(%myVar%)
    MsgBox %myNewVar% 
    return

TestFunction(arg)
{
    MsgBox arg
    msgBox %arg%
    return %arg%
}    

What I'm looking to do is setup a hotkey that will prompt for a keyword for an app, then evaluate what is entered in the function and fire up whatever app corresponds to that keyword.

Thanks!

Chris

Best Answer

I've corrected your script (like Bavi_H suggested) and added an example to launch an application corresponding to a keyword.

#t::
inputbox myVar, What is your variable?
myNewVar := TestFunction(myVar)
MsgBox %myNewVar% 
return

TestFunction(arg)
{
    msgBox %arg%
    if (arg = "calc")
    {
        run, calc.exe
    }
    else if (arg = "word")
    {
        run, winword.exe
    }
    return arg . "bob"
}
Related Question