How to get global mouse coordinates in python without using PyautoGUI (Windows and Wayland/Fedora)
11:53 21 Jan 2026

I'm looking for a way of retrieving the current X and Y coordinates of the mouse cursor in python without using the PyAutoGUI library. pyautogui.position() works, but I want to avoid dependencies like pillow that come with it.

Current placeholder code:

import pyautogui
import time

try:
    while True:
        x, y = pyautogui.position()
        print(f"X={x}, Y={y}")
        time.sleep(2)
except KeyboardInterrupt:
    pass

Requirements:

Must work on Windows 11/10 (obviously with Python installed) and Fedora-based Linux distros using Wayland

Must use lightweight 3rd party libraries, or even better, ctypes

python linux mouseevent pynput