1
votes

There is a description of how to define a custom combination in AutoHotkey:

You can define a custom combination of two keys (except joystick buttons) by using " & " between them. In the below example, you would hold down Numpad0 then press the second key to trigger the hotkey:

Numpad0 & Numpad1::MsgBox "You pressed Numpad1 while holding down Numpad0." 
Numpad0 & Numpad2::Run "Notepad" 

But I couldn't find how to set the threshold. for example, I want Numpad0 & Numpad1 only to happen when user presses Numpad1 in less than 300ms after pressing Numpad0.

1

1 Answers

1
votes

You could do something like this for example:

Numpad0::
    if (!PressedAt)
        PressedAt := A_TickCount
return

Numpad0 Up::PressedAt := 0


#If, A_TickCount - PressedAt < 300
Numpad1::MsgBox
#If

So use A_TickCount(docs) to compare times.
And the if-statement is there because of Windows' key repeat functionality. Without it, the PressedAt time would get set constantly while Numpad0 is held down.
Also, 0 is false, so we can conveniently use the PressedAt variable in the if-statement as well.

Could've also be done without a context sensitive hotkey for Numpad1, it just makes the key retain its original functionality.
If #If were to cause you trouble, you can switch over to a normal if-statement check inside the hotkey label.

And be sure to add the ~ prefix(docs) to the Numpad0 hotkey if you want.