Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
1  
When you call the function, you don't need percent signs around the parameter: myNewVar := TestFunction(myVar) –  Bavi_H Feb 8 '11 at 4:56
    
Bavi is right (he should have put his answer in an Answer): parameters called by a function need function("string") if they are strings, and just function(variable) (no percentage signs) if they are variables. It works if you just remove the percentage signs in your third line. I know how incredibly frustrating percentage signs and quotation marks can be in AHK: they kill me too from time to time. –  Cerberus Feb 20 '11 at 23:40

1 Answer 1

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"
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.