AHK — How to interrupt alternate keys for same hotkey?

1

I have a code that every time I press the hotkey, a letter is sent.

Pressing Q, Q, Q, Q, Q is sent "a", "b", "c", "d", "e", respectively. Then the loop restarts.

For example: pressing Q 13 times sends "abcdeabcdeabc".

My question is:

How can I reset the loop and return to the first letter ("a") if I do not press Q for a few seconds?

My code:

q::
Send, % ["a","b","c","d","e"][(count >= 5 || !count)? count := 1 : ++count]
return

rdllngr

Posted 2017-09-22T03:17:53.220

Reputation: 141

Your question is difficult to understand. What do you mean by [ Combo Break ]? How should AHK respond if you intend to press Q three times, but pause after the first keypress (should it send a)? – I say Reinstate Monica – 2017-09-22T20:30:42.597

1Excuse me. This was really confusing. Let me try to explain:

Every time I press Q, a letter in the loop is sent. Example: pressing Q, Q, Q, Q, Q, Q, Q, Q = sends "a", "b", "c", "d", "a", "b", "c", "d".

What I needed was a way to reset the loop if I did not press Q for a while. Example: pressing Q, Q, Q, (so do not press Q for few seconds), and then Q again = "a", "b", "c", (after idle), "a" again (not "d"). The loop restarted after idle. – rdllngr – 2017-09-22T21:04:15.170

That makes a lot more sense! Please consider editing your question so that others can benefit from the answer you found. – I say Reinstate Monica – 2017-09-22T21:51:19.117

With pleasure. Thanks for the instruction. :) – rdllngr – 2017-09-22T23:02:58.777

Answers

2

I found a solution by myself. I hope this can help someone in the future.

Good luck. :)

q::
Send, % ["a","b","c","d","e"][A_TimeSincePriorHotkey>2500 || A_PriorHotkey<>A_ThisHotkey || (count >= 5 || !count) ? count := 1 : ++count]
return

rdllngr

Posted 2017-09-22T03:17:53.220

Reputation: 141