gitmyhub

pyautogui

Python ★ 13k updated 1y ago

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.

A Python library that controls your computer's mouse and keyboard through code, move the cursor, click buttons, type text, press shortcuts, take screenshots, and click on-screen images, all without touching the actual input devices.

Pythonsetup: easycomplexity 2/5

PyAutoGUI is a Python library that lets you control your computer's mouse and keyboard through code. Instead of clicking around manually, you can write a script that moves the mouse to a specific position, clicks buttons, types text, or presses keyboard shortcuts, all without touching the actual input devices. This is useful for automating repetitive tasks on your desktop, like filling out forms, copying data between applications, or running the same sequence of actions over and over.

The library works on Windows, macOS, and Linux. On each platform it speaks to the operating system using that platform's native programming interfaces, but it hides those technical details behind a simple set of Python functions. To move the mouse and click, you call moveTo() followed by click(). To type text, you call write() with the text as input. Keyboard shortcuts like Ctrl+C can be sent with a single hotkey() call.

Beyond controlling the mouse and keyboard, PyAutoGUI can take screenshots and search the screen for a specific image. You can save a small screenshot of a button, then have the library scan your screen and click wherever that button appears. This makes it possible to automate interactions with applications that don't provide their own scripting support.

The library also includes simple pop-up dialog boxes, so scripts can ask the user a question or display an alert and wait for a response before continuing.

One limitation noted in the README: PyAutoGUI only works reliably with your primary monitor. Multi-monitor setups may produce unpredictable results depending on the operating system. Installation requires a single pip command. Linux and macOS users need to install a couple of additional packages manually, while Windows users can get started without any extra steps.

Where it fits