just replace the sleep(5); with:

while(mouse_middle==0){wait(1);}