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.

Gabriel Cesar
  • 197
  • 1
  • 3
  • 10

3 Answers3

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)
Atto
  • 154
  • 8
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.

zacm
  • 91
  • 6
-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

wishmaster
  • 1,237
  • 5
  • 14