Search code examples
autohotkeywindows-11ahk2

How do I use a variable to define key up/down?


test(key){
    send "{key down}" ;no
    ; send "{%key% down}" ;no
    sleep 500
    send "{key up}"
}
test("w") ;test(w) doesnt work either as per the manual

%key% works in AutoHotkey v1. For AutoHotkey v2 it says this works but it doesn't :

if InStr(MyVar, "fox")
    MsgBox "The variable MyVar contains the word fox."

Solution

  • key:="up"
    send "{" key " down}" 
    

    is equivalent to

    send "{up down}"