This comes late after your post (almost two years).
I was looking for how to distinguish single and double taps (or presses), and am grateful for your macro.
When I tried to document it for my own purposes, I found a number of simplifications, and I may be wrong or have overlooked something. But here is my version:
HotKey MultiPress Template.kmmacros (11.1 KB)
Comments in general on this way of solving the multi-press problem:
a) It relies on the delay to be longer than any sequence of decision statements to be executed.
b) When trying to understand what is going on, the complexity is caused by having five separate processes collapsed into one piece of code:
1-setting the delay and limit constants
2-restarting a pause at each press
3-counting the number of presses
4-doing the desired actions when a pause times out
c) Normally these processes communicate with each other and run independently, as they would in e.g. Modula.
d) In a summarising language (not Modula):
1 put 0.2 into delay
2 put 5 into limit
4 lock Running
5 if already locked then --"timeout exceeded"
6 if active <= limit then
7 increment active
10 put 1 into active
11 put 0 into count
13 while active > count
14 put active into count
15 pause delay
18 case count
19 1: …
20 2: …
23 delete variables
Since there are no constant declarations, lines 1 and 2 must be executed at each press.
We start a new pause each time there is a press within the current pause. To detect that we are in a pause, we lock a semaphore "Running" (line 4): at each press we try to lock it again and count an additional press if it fails and terminate the current instance (lines 5-8)
There seems to be no need for the second semaphore nor for some other assignments.
The case statement ("switch" in C-like languages) finally does the desired action depending on the count of presses (lines 18-20).
It seems to work for me: I'm using Keyboard Maestro to type French on a US extended keyboard where I use the Fn keys for accents. F1 to F5 type â,ê,î,ô,û but I also need ù sometimes, so I configured it so that pressing F5 twice gives me ù.
Hopefully you find something dreadfully wrong with this version.