Pyautogui mouse clicks without actually moving the mouse
Asked Answered
I

3

10

I'd like to know if it's possible to automate clicks with pyautogui without compromising the funcionality of my cursor. I automate clicks with pyautogui but my cursor becomes useless while the script is running as the cursor moves around the screen. I was wondering if it is possible to either 1) have two cursos and have pyautogui automating one while I operate the other myself, or 2) have pyautogui click on the screen without actually moving my cursor.

Invar answered 17/6, 2018 at 23:15 Comment(0)
R
8

I'm guessing the OS (like most of them) does not have support for multiple mouse pointers. This means that pyautogui does not have it either. The closest you can get to the behavior you are describing is to save your current mouse position with pyautogui.position(), then pressing where you want to press and then jumping back to that position. When done quickly you will have control of your mouse pointer between the automated clicks.

Example:

# Save mouse position
(x, y) = pyautogui.position()
# Your automated click
pyautogui.click(200, 300)
# Move back to where the mouse was before click
pyautogui.moveTo(x, y)
Rapping answered 21/6, 2018 at 7:47 Comment(0)
H
1

PyAutoGui to my knowledge does not support this functionality, however, at least according to this thread here, using autoit with the function ControlClick allows simulated mouse clicks without any associated cursor movement.

Hyposthenia answered 5/2, 2019 at 1:52 Comment(0)
R
-1

first solution is to save the current mouse location then return to it after mouse click as follows

import pyautogui
(x,y)=pyautogui.position()
pyautogui.click(600,300)
pyautogui.moveTo(x,y)

second solution is to make a keyboard shortcut for the button then simply pressing the button without moving the mouse

Rogelioroger answered 31/1, 2019 at 9:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.