What are you attempting to achieve?
just I'm going on with the idea to shrink the initial codeloop of Krovit...
why? It was a challange to me to achieve a mouse manager with one loop... just to think different and not to think doing better than previous examples of code posted.
And I got a one loop with echo of the one click event after a dragging and / or doubleclick event! :-)
After looking at variables initialization with tedious and verbose printing on the screen I see that also resetting variables
the parser of mouse events takes again inputs from mouse also if there was no more input... so the stack of mouse input is the only reason for getting this experience...