functionreturnautohotkeyautohotkey-2

How do I setup a function call to end a hotkey?


I want to use breakout(var) instead of typing that if statement a million times. How do I make that work? Return returns from the function but I want to end the hotkey.

f::{
    send "a"
    sleep 1000

    if (A_PriorKey!="f" and A_PriorKey!=""){
      return ;does the desired behaviour, but I want to use breakout("f") instead of 3 liner if statments
    }
    ;breakout("f")

    send "a"
    sleep 1000
}


breakout(var){
    if (A_PriorKey!=var and A_PriorKey!=""){
        return
    }
}

If I press F, after 1000ms it checks if I pressed any other key since the hotkey began. If I did it ends the hotkey early.


Solution

  • Hotkeys are started in a new thread, which means you can use Exit to kill the thread, effectively achieving what you want.

    breakout(var){
        if (A_PriorKey!=var and A_PriorKey!=""){ 
            Exit
        }
    }