asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.37k stars 1.26k forks source link

pyautogui does not interact with the mouse #279

Open executionByFork opened 5 years ago

executionByFork commented 5 years ago

I created a stackoverflow question about this here, but it seems no one has any solutions to my problem. The linked post has the details and visually shows the issue I am having, but the basic problem is that pyautogui is not moving my visual mouse pointer. Additionally, when I run a script, moving my mouse to the top left corner does not stop the script. Strangely, the script still works as long as I do not move my mouse, as if the library is interacting with an invisible mouse.

What is going wrong and how might I fix it?

I am running Ubuntu 18.04 LTS, and it is essentially a fresh install. Please see my link to the stackoverflow question for the photo example and more detail.

executionByFork commented 5 years ago
$ pip freeze
numpy==1.15.4
opencv-python==3.4.3.18
Pillow==5.3.0
PyAutoGUI==0.9.38
PyMsgBox==1.0.6
PyScreeze==0.1.18
PyTweening==1.0.3
six==1.11.0
xlib==0.21

Additionally, see my other issue I opened. Perhaps they are related. #280

dchen327 commented 5 years ago

Were you ever able to fix the issue? I am having the same issue on a chromebook running crostini.

executionByFork commented 5 years ago

I have not found a fix

Gabriel-Nunes commented 5 years ago

Try to run the Python IDLE as Admin.

Gabriel-Nunes commented 5 years ago

Try to use just one display/monitor. It works for me.

dchen327 commented 5 years ago

Try to use just one display/monitor. It works for me.

I have tried with only one display. Are you using Crostini?

Gabriel-Nunes commented 5 years ago

I'm using Mint. It may be regarding your OS so

Nyx128 commented 3 years ago

I'm using Manjaro Linux ,i seem to be able to use typewrite and keyboard functions and my program compiles just fine but my mouse functions don't work at all

chauanphu commented 3 years ago

It seems that after you install the pyautogui and its following packages, you should restart the computer. At first my pyautogui on my ubuntu doesn't read pixel nor interact with mouse. But after restarting, now it works like a charm

AliHaiderPAK commented 2 years ago

Its so frustrating, I am having this issue on Ubuntu. The click functions work fine but the cursor doesn't move an inch. Has anyone found the fix?

skyler-murray commented 2 years ago

When I was running into this it was because I wasn't running from an administrator level.

whitelowrie commented 2 years ago

@AliHaiderPAK hi, About the mouse doesn't move , dou you have some solution?

AliHaiderPAK commented 2 years ago

Hi @whitelowrie yes I resoleved that issue two months ago but currently its out of my mind that how I did it:-), are you having this issue on linux?

AliHaiderPAK commented 2 years ago

@whitelowrie its was something related to "sudo xkeysnail config.py"

kiddiemano commented 2 years ago

@AliHaiderPAK I can't able to move the mouse either. How exactly you rectify this issue?

danielcode2020 commented 1 year ago

am facing the same issue on ubuntu 22.04 LTS, tried sudo python3 _scriptname.py , installed the pyautogui dependency with sudo but no success

danielcode2020 commented 1 year ago

for ubuntu, switching from waylang to xorg worked for me. Follow this link https://beebom.com/how-switch-between-wayland-xorg-ubuntu/#:~:text=On%20the%20password%20screen%2C%20you,select%20%E2%80%9CUbuntu%20on%20Wayland%E2%80%9D.

JayRizzo commented 1 year ago

Hi All, I hope everyone is doing well.

Now I am on a mac, but the issues with click() "not working" I have seen before. Over the last few years I have also run into this a few times. What fixed it for me was utilizing a virtual environment or doing a complete python wipe & reinstall.

Also I believe there are some packages that cause issues, I never found what or why but it does sometimes cause strange behavior & Virtual Environment seems to maintain the behaviour.

If you get a chance try this (Code Blocks are setup for copy-pasta):

VENV

cd ~/
mkdir Test
cd Test 
python3 -m venv ~/Test
source ~/Test/bin/activate

pip install --upgrade pip
pip install pyautogui
pip install pyobjc
pip install pyobjc-core
pip freeze

# this is what i got right now
# MouseInfo==0.1.3
# PyAutoGUI==0.9.53
# PyGetWindow==0.0.9
# PyMsgBox==1.0.9
# pyobjc==9.0.1
# pyobjc-core==9.0.1
# pyobjc-framework-*==9.0.1 # there are a bunch of these. i combined them for ease of reading. all the same verison 9.0.1
# pyperclip==1.8.2
# PyRect==0.2.0
# PyScreeze==0.1.28
# pytweening==1.0.4
# rubicon-objc==0.4.3

python

Python Test:

import pyautogui

pyautogui.position()
pyautogui.move(284, 202)
pyautogui.click()
# or try being explicit:
pyautogui.click(x=284, y=202, clicks=1, interval=0.0325, button="left")

Behaviour

pyautogui controls mouse clicks differently for 'darwin' os system as seen here.

Alternative

If that still fails, you can try my approach from stackoverflow.

Or try a specific version & retry your tests:

pip install 'pyautogui==0.9.44'

The specific version was my work-around to fix my issues, I ran into.

Contributions

I later contributed to some fixes for mac with mouse behaviour to help resolve the issue.

Code References

This fixed my issue when I was writing some code to play "Realm Grinder" Game: https://github.com/JayRizzo/rg_code

I hope this helps! Good Luck!

Don't have a Good Day, Have a Great Day!

Adarsh810864 commented 1 year ago

having same isssue

demensdeum commented 9 months ago

Same problem Wayland, cursor does not move

Scoobylolo commented 7 months ago

I was having the same issue in a windows VM and I solved it by passing the duration parameter. Anything lower than 0.7 didn't work. Restarting the pc after installing pyautogui also didn't work. pyautogui.moveTo(1500, 1000, duration=0.7)

This is my version (from pip):

Name: PyAutoGUI
Version: 0.9.54