pythonautomationpyautogui

Python automating mouse click without 'using' my mouse


I would like to know if there is a way to make automated clicking tasks without making me unable to use the mouse on my pc to do other stuff. I mean, I want to use the pc normally with the main monitor while on the second monitor python would be performing some clicks.


Solution

  • You can do this in Loop, while changing input arguments of function. This is one way of doing it inside you Windows. You can define your locations (x,y) on plan. it will keep on doing things inside your VM.

    import win32api, win32con
    def click(x,y):
        win32api.SetCursorPos((x,y))
        win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,x,y,0,0)
        win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,x,y,0,0)
    click(100,100)