not really works, cause the MOUSEEVENTF_LEFTUP it stop the held, but if i set MOUSEEVENT_LEFTDOWN after MOUSEEVENT_LEFTUP it'll infite loop but can't be stoped.
I think you still need an extra condition.
I think you need
while (hardware is down) //loop
{ //your function body
left up event
left down event
if hardware is up
left up event again //this should help stop the while loop, if I understand the issue
}
so that if the hardware is up, it sends the up event as the last thing seen, which should stop the while loop. If that does not work, you can also try putting an 'if hardware up, send up and return' at the top of the function.