My approach would be with a variable, initially 0, and a short timer (the gap allowed between key presses before it is determined that it's a single key press).
When you press the key, add 1 to the variable. On timer, end if variable is 2 then it's a double click, if 3 it's a triple click. On timer end also set variable back to 0.