Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to simulate a mouse click and drag?

I want to simulate an event where I left click on the Windows desktop, I drag the mouse a little to create a Selection box to another point, and then keep holding the left button at that point for some time without the Selection box disappearing.

The problem is, I can't get him to keep the Selection box, whenever he gets to the other point the Selection box disappears indicating that the button has been released.

I tried to implement in Python using PyAutoGUI. I tried several ways to do this but still unsuccessfully. Is there any function I'm missing?

import time
import pyautogui

time.sleep(3)

while True:
    pyautogui.moveTo(1080, 380)
    pyautogui.mouseDown(button='left')
    pyautogui.dragTo(917, 564, 1, button='left')
    time.sleep(10)
    pyautogui.mouseUp(button='left')
    time.sleep(2)
like image 425
Erick Lopes Avatar asked Oct 27 '22 10:10

Erick Lopes


1 Answers

Simply removing 2 lines of code and changing dragTo() to moveTo() seems to do what you are trying to do:

import time
import pyautogui

time.sleep(3)

while True:
    pyautogui.moveTo(1080, 380)
    pyautogui.mouseDown(button='left')
    pyautogui.moveTo(917, 564, 1)
    time.sleep(10)
like image 151
Alt Avatar answered Nov 15 '22 06:11

Alt