The middle mouse button in the example, but it can be any of the available mouse buttons; the loop just needs to check the same button you use to trigger the command.
What you have in your screenshot looks correct; what doesn't appear to be working?
Note that if the "Do not allow button event to be passed through" option is enabled, the loop cannot detect the button press