简体   繁体   中英

Mouse click and Drag in python

I'm trying to do a very simple task, 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 other library that can help me, any function I'm missing? I am new to python and am still learning.

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)

Not sure if you figured out the answer to your problem considering this was 10 months ago but 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)

I'm new too , However, as far as I've searched for it and found something interesting which maybe could help you a bit:

pyautogui.moveTo(1277 ,127)

pyautogui.dragTo(1277 , 225, button='left', duration=5)

(duration=5 = 5 secs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM