Dynamic default key action

21 Views Asked by At

I'm trying to create a script that will trigger key numbers from 1 to 3

I was trying:

KeyNum := 1
1:: {   
    global KeyNum 
    Send KeyNum 

    KeyNum := KeyNum + 1
    
    if (KeyNum > 3) {
        KeyNum := 1
    }
}

but the output was 232323, so I changed it to:

KeyNum := 1
~1:: {      
    global KeyNum 
    Send KeyNum 

    KeyNum := KeyNum + 1
    
    if (KeyNum > 3) {
        KeyNum := 1
    }
}

but then I got 111213111213

How can I prevent default action in the ~1:: version?

or

How can I call the default key action in the 1:: version?

I found that question but I don't know is it possible to implement it in my case.

1

There are 1 best solutions below

0
0x464e On BEST ANSWER

You want the $(docs) prefix.

#Requires AutoHotkey 2

$1::
{
    static num := 1
    SendInput(num++)
    if (num > 3)
        num := 1
}