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:

Send, % ["a","b","c","d","e"][(count >= 5 || !count)? count := 1 : ++count]
  • 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 Sep 22 '17 at 20:30
  • 1
    Excuse 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 Sep 22 '17 at 21:04
  • 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 Sep 22 '17 at 21:51
  • With pleasure. Thanks for the instruction. :) – rdllngr Sep 22 '17 at 23:02

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

Good luck. :)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.