简体   繁体   中英

Pyautogui mouse drag to not gradual

I'm using pyautogui , then I used .dragTo() to basically draw a square. The top left and right corners of the square are (25, 340) and (450, 340). And the bottom left and right corner of the square is [25, 700] and [450, 700]. Here is my square code:

pyautogui.dragTo(25, 340, duration=0.5)
pyautogui.dragTo(25, 700, duration=0.5)
pyautogui.dragTo(450, 700, duration=0.5)
pyautogui.dragTo(450, 340, duration=0.5)

I open up the paint app, and it draws the square. The problem is, I see the mouse gradually move during each line, but the line on the paint app doesn't follow it. The line appears completely at once after each line fully completes. How do I make the line come gradually?

Please let me know if you need any additional clarification.

Thanks!

In your program you are telling it to take 0.5 of a seconds to complete this action. You can decrease or increase this to create or remove a dragging effect. I have also added a line that moves your mouse to the first point of the square so there are no strange angles.

# With Extra Drag
# Move mouse with no click
pyautogui.moveTo(450,340)

# pyautogui.dragTo(<co-ordinates x,y>, <duration=How long per movement incrasing or decreasing our drag
pyautogui.dragTo(25, 340, duration=5)
pyautogui.dragTo(25, 700, duration=5)
pyautogui.dragTo(450, 700, duration=5)
pyautogui.dragTo(450, 340, duration=5)

Now with drag removed (Mostly this will still take some time but increase any further and it may be too quick for your program) as tested in MS paint

pyautogui.moveTo(450,340)

pyautogui.dragTo(25, 340, duration=0.1)
pyautogui.dragTo(25, 700, duration=0.1)
pyautogui.dragTo(450, 700, duration=0.1)
pyautogui.dragTo(450, 340, duration=0.1)

Some examples of this transition time (slow) 花时间过渡

This method also removes the odd angles in your code with the pyautogui.moveTo(x,y)

Ask if you have any issues, sorry if this is not your issue you where a bit inspecific with your question.

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