'Stimulate REAL mouse release event

I am trying to trigger a mouse left click event then release that click so it should be like a real mouse click.

I am currently doing it like that:

def click(x,y): 
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

I've also tried pynput like that:

mouse.click(Button.left)

and:

mouse.press(Button.left)
mouse.release(Button.left)

So, all the three codes works fine and they almost work the same way... But try a real mouse click on https://cookie.riimu.net/speed/ then try the click made using Python on the same site.

So as you can see, in the real mouse click: the circle pops in then pops out. But in the Python mouse click, the circle pops in and doesn't pop out again.

What can be causing that? And is there's any possible fix?



Solution 1:[1]

30 milliseconds is a correct delay between the click and the release.

So this would stimulate a real left mouse click and release:

def click(x,y): 
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    time.sleep(30 / 1000)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gave