explaingit

asweigart/pyautogui

12,496PythonAudience · developerComplexity · 2/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((pyautogui))
    What it does
      Mouse control
      Keyboard typing
      Screenshot capture
      Image-based clicking
    Platform support
      Windows
      macOS
      Linux
    Key functions
      moveTo and click
      write and hotkey
      screenshot and locate
      Dialog pop-ups
    Limitations
      Primary monitor only
      GUI apps only
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Write a Python script to automate filling out a repetitive desktop form by moving the mouse, clicking fields, and typing text.

USE CASE 2

Use screenshot matching to find and click a button wherever it appears on screen, even in apps with no scripting API.

USE CASE 3

Automate a multi-step sequence of keyboard shortcuts across different desktop applications without manual input.

USE CASE 4

Add a script-driven pop-up dialog to a Python automation so it can ask the user a question before continuing.

Tech stack

Python

Getting it running

Difficulty · easy Time to first run · 5min

Windows works with pip install alone, Linux and macOS require a couple of extra system packages. Unreliable on multi-monitor setups.

No license information is mentioned in the explanation.

In plain English

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.

Copy-paste prompts

Prompt 1
Using PyAutoGUI, write a Python script that takes a screenshot every 5 minutes and clicks a specific button image if it appears anywhere on screen.
Prompt 2
Show me how to use PyAutoGUI to copy data from a legacy Windows desktop application by reading its fields and pasting into a spreadsheet.
Prompt 3
Write a PyAutoGUI script that opens a browser, navigates to a URL, fills in a login form, and downloads a file from the resulting page.
Prompt 4
How do I use PyAutoGUI's locateOnScreen to click a button that moves position each time the app opens?
Open on GitHub → Explain another repo

← asweigart on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.