[Python] pyautogui is not updaing mouse position on Raspberry

Discussão em 'Python' iniciado por Stack, Janeiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I try to get the mouse position on my Raspberry 4. I used pyautogui in the past, which was working fine. But on the Raspberry the mouse position returned by pyautogui is stale. Other functions on pyautogui works fine.

    Here are some details OS:

    PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
    NAME="Debian GNU/Linux"
    VERSION_ID="12"
    VERSION="12 (bookworm)"
    VERSION_CODENAME=bookworm
    ID=debian
    HOME_URL="https://www.debian.org/"
    SUPPORT_URL="https://www.debian.org/support"
    BUG_REPORT_URL="https://bugs.debian.org/"


    A note to the pyautogui installation: when using the recommeded command I get the following error: python3 -m pip install pyautogui error: externally-managed-environment

    × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install.

    If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed.

    with the installation: sudo pip3 install pyautogui --break-system-packages ... ok - pyautogui-Version: 0.9.54

    the installation went ok. Functions works in my python (Python 3.11.2).

    example code:

    import pyautogui, sys
    print("pyautogui : ",pyautogui.__version__)
    print("Screen size: ",pyautogui.size())
    pyautogui.alert("PyAutoGUI-Alert")
    x, y = pyautogui.position()
    print("X:",x," Y:",y)
    pyautogui.moveTo(100, 150)
    x, y = pyautogui.position()
    print("X:",x," Y:",y)
    print("End")


    result: pyautogui : 0.9.54 Screen size: Size(width=1920, height=1080) X: 500 Y: 268 X: 100 Y: 150 End

    The result of the mouse position is incorrect - it looks stale, when you put it in a loop.

    Any idea or hints are welcome. regards, HEP

    Continue reading...

Compartilhe esta Página