Install PyAutoGUI, import it, and call pyautogui.click(). With no coordinates, it clicks wherever the pointer is. Pass x and y to move to a screen coordinate and click in one call. Coordinates start at (0, 0) in the top-left corner of the primary screen, with x increasing to the right and y increasing downward.
Install PyAutoGUI
Use the Python launcher or interpreter that will run your script:
Windows
py -m pip install pyautogui
macOS
python3 -m pip install pyautogui
Linux
python3 -m pip install pyautogui
The project’s Linux installation guidance also lists scrot, python3-tk, and python3-dev as prerequisites. Install those with your distribution’s package manager if PyAutoGUI reports that a screen-capture or Tk component is missing.
Your first PyAutoGUI click
This complete example enables the two controls that make desktop automation easier to observe and stop safely:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match#1 Best Overall
- Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
- Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
- Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
- Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
- Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)
import pyautogui
pyautogui.FAILSAFE = True
pyautogui.PAUSE = 0.1
# Click at the pointer's current position
pyautogui.click()
PAUSE inserts a short delay after each public PyAutoGUI call. A value such as 0.1 makes a script visible enough to debug while still being quick. Keep FAILSAFE enabled during development.
Click at an x/y coordinate
Pass keyword arguments to move and click in one operation:
import pyautogui
pyautogui.FAILSAFE = True
pyautogui.PAUSE = 0.1
pyautogui.click(x=100, y=200)
Here, (100, 200) means 100 pixels to the right and 200 pixels down from the primary display’s top-left corner. The coordinates are absolute screen coordinates, not coordinates relative to the active window.
Move first, then click
Separating the move is useful when you want to watch the pointer approach the target or inspect a failure:
Rank #2
- Pair and Play: With fast, easy Bluetooth wireless technology, you’re connected in seconds to this quiet cordless mouse —no dongle or port required
- Less Noise, More Focus: Silent mouse with 90% reduced click sound and the same click feel, eliminating noise and distractions for you and others around you (1)
- Long-Lasting Battery Life: Up to 18-month battery life with an energy-efficient auto sleep feature, so you can go longer between battery changes (2)
- Comfortable, Travel-Friendly Design: Small enough to toss in a bag; this slim and ambidextrous portable compact mouse guides either your right or left hand into a natural position
- Long-Range: Reliable, long-range Bluetooth wireless mouse works up to 10m/33 feet away from your computer (3)
import pyautogui
pyautogui.moveTo(100, 200, duration=0.2)
pyautogui.click()
A short, visible duration helps you confirm that the pointer reaches the intended control. A duration shorter than PyAutoGUI’s minimum-duration threshold can be treated as an immediate move.
Choose the button, count, and interval
| Goal | Code | What it does |
|---|---|---|
| Left click | pyautogui.click() |
Uses the default left mouse button. |
| Right click | pyautogui.click(button='right') |
Opens a context menu or performs the target’s right-button action. |
| Middle click | pyautogui.click(button='middle') |
Sends a middle-button click. |
| Double-click | pyautogui.click(clicks=2, interval=0.25) |
Sends two clicks with a quarter-second gap. |
| Named double-click | pyautogui.doubleClick(x=100, y=200) |
Moves to the coordinate and performs a double-click. |
| Named right-click | pyautogui.rightClick(x=100, y=200) |
Moves to the coordinate and right-clicks. |
| Named middle-click | pyautogui.middleClick(x=100, y=200) |
Moves to the coordinate and middle-clicks. |
The same x, y, clicks, interval, and button ideas can be combined. For example:
pyautogui.click(x=640, y=420, button='right', clicks=2, interval=0.2)
Use a separate move when you need a controlled approach:
pyautogui.moveTo(640, 420, duration=0.25)
pyautogui.click(button='left', clicks=2, interval=0.2)
Inspect the screen before clicking
Hard-coded coordinates are only meaningful for the screen layout in which you measured them. Print the pointer location and screen dimensions while developing:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Rank #3
- 【Dual Mode Wireless Bluetooth Mouse】: Switch easily between two devices—connect one via Bluetooth (BT5.2/3.0) and the other using a 2.4G USB receiver. No drivers needed; just plug and play. Enjoy a reliable connection up to 33 feet. Note: You can't use both modes simultaneously; the USB receiver is stored in the mouse.
- 【Rechargeable Wireless Mouse】: Equipped with a 500mAh lithium-ion battery, it charges in 2 hours for over 7 days of use and 30 days on standby. The mouse sleeps after 5 minutes of inactivity to save power and can be woken with any click.
- 【Colorful LED Breathing Light】: Features 7 colorful LED lights that change randomly, adding a fun atmosphere to your workspace.
- 【Portable Mouse】Compact size (4.4 x 2.3 x 1.1 inches) makes it easy to fit in your laptop bag. Lightweight and ergonomic, it's perfect for travel. Contact us anytime for support.
- 【Wide Compatibility】: Works with laptops, PCs, tablets, and smartphones across various operating systems, including Android, Windows, and Mac. Ideal for home, office, and travel.
import pyautogui
print('Pointer:', pyautogui.position())
print('Screen:', pyautogui.size())
Check a candidate coordinate before using it:
x, y = 100, 200
if not pyautogui.onScreen(x, y):
raise ValueError(f'Coordinate {(x, y)} is outside the screen')
pyautogui.click(x=x, y=y)
onScreen() prevents an obvious out-of-bounds mistake; it does not prove that a button is at that location. Confirm the target visually, especially after moving or resizing a window.
Use fail-safe and timing controls
Fail-safe stop
With pyautogui.FAILSAFE = True, moving the mouse to the upper-left corner raises pyautogui.FailSafeException and can abort the program. This gives you a physical escape route if a loop starts clicking the wrong place.
import pyautogui
pyautogui.FAILSAFE = True
try:
pyautogui.click(x=100, y=200)
except pyautogui.FailSafeException:
print('Stopped by moving the pointer to the upper-left corner')
Do not deliberately disable fail-safe mode until you have another reliable way to stop the process.
Pause between actions
pyautogui.PAUSE = 0.15
pyautogui.moveTo(100, 200, duration=0.2)
pyautogui.click()
The global pause applies after each public PyAutoGUI call. Use it to let a window repaint or a menu open before the next action. For a one-off delay, structure the moves and clicks separately so the timing is visible in your code.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsRank #4
- Your hand can relax in comfort hour after hour with this ergonomically designed mouse. Its contoured shape with soft rubber grips, gently curved sides and broad palm area give you the support you need for effortless control all day long.
- You’ve got the control to do more, faster. Flipping through photo albums and Web pages is a breeze, especially for right-handers—with three standard buttons plus Back/Forward buttons that you can also program to switch applications, go full screen and more. And side-to-side scrolling plus zoom gives you the power to scroll horizontally and vertically through your music library, maps and Facebook feeds, and zoom in and out of photos and budget spreadsheets with a click.* * Requires Logitech SetPoint software (Windows) or Logitech Control Center software (Mac OS X)
- Two years of battery life practically eliminates the need to replace batteries. ** The On/Off switch helps conserve power, smart sleep mode extends battery life and an indicator light eliminates surprises. ** Battery life may vary based on user and computing conditions.
- The tiny Logitech Unifying receiver stays in your laptop. There’s no need to unplug it when you move around, so there’s less worry of it being lost. And you can easily add compatible wireless mice and keyboards to the same wireless receiver.
Press and release manually
For a custom press/release sequence, use mouseDown() and mouseUp() instead of the convenience function:
import pyautogui
pyautogui.moveTo(300, 250, duration=0.2)
pyautogui.mouseDown(button='left')
# Perform any operation that must happen while the button is held.
pyautogui.mouseUp(button='left')
This is the building block for a drag-like gesture or any interaction where the press and release must be separated. Keep the fail-safe enabled while experimenting.
A reusable click script
The following script validates the coordinate, shows the move, and then performs a configurable click:
import pyautogui
pyautogui.FAILSAFE = True
pyautogui.PAUSE = 0.1
x, y = 640, 420
button = 'left'
clicks = 1
interval = 0.15
if not pyautogui.onScreen(x, y):
raise ValueError(f'{(x, y)} is outside the current screen')
print('Screen size:', pyautogui.size())
print('Starting pointer:', pyautogui.position())
pyautogui.moveTo(x, y, duration=0.25)
pyautogui.click(button=button, clicks=clicks, interval=interval)
Change x, y, button, clicks, and interval for the interaction you need. Measure the coordinate on the same display arrangement and scaling used when the script runs.
Free tools Windows power users keep installed
One-click scans. No signup required.
Best Value
- 【Plug and Play for Home/Office/School】The wireless computer mouse features 2.4GHz connectivity, delivering a stable, interference-free connection up to 32ft. Designed for 𝐦𝐞𝐝𝐢𝐮𝐦 𝐭𝐨 𝐥𝐚𝐫𝐠𝐞 𝐬𝐢𝐳𝐞𝐝 𝐡𝐚𝐧𝐝𝐬, it ensures comfortable use all day. Simply plug in the USB-A receiver for instant pairing—no drivers needed. 📌📌 If the mouse isn’t suitable, place the USB receiver in the battery compartment and return both.
- 【3 Levels Adjustable DPI】This travel USB mouse offers 3 adjustable DPI settings (800, 1200, 1600), allowing you to customize sensitivity for precise design work. Effortlessly switch to match your task and elevate your productivity. 📌 Please remove the film at the bottom of the mouse before use.
- 【Effortless Browsing】Equipped with forward and backward buttons, this computer mice streamlines your workflow, making it easy to navigate through web pages and files with a simple click. 📌Side button does not work on Mac.
- 【Visible Indicator Light】 The pc mouse features a visual indicator for DPI levels and low battery alerts. The red light flashes once for 800 DPI, twice for 1200 DPI, and three times for 1600 DPI. When the battery level is below 10%, the light flashes red until the mouse is completely out of power.
- 【Click to Wake】With smart sleep mode, it saves power by standby after 10 inactive minutes, just 2-3 clicks to wake. This efficient design delivers 3x longer battery life than motion-wake mice. Engineered for durability, its buttons and scroll wheel are tested for 10 million clicks, ensuring long-term reliability and consistent performance.
Why a PyAutoGUI click misses
| Symptom | Likely cause | Fix |
|---|---|---|
| The pointer lands beside the control | Display scaling, resolution, window position, or monitor arrangement changed. | Print pyautogui.size(), re-check the visible coordinate, and measure again in the runtime environment. |
| The click happens before the control appears | The application is still loading or repainting. | Set a small PAUSE, move with a short duration, and split the move and click so you can observe the state. |
| Nothing receives the click | The target window is not focused. | Bring the intended window to the foreground manually and verify the pointer is over it before running the script. |
The script stops with FailSafeException |
The pointer reached the upper-left fail-safe corner. | Move the pointer away from that corner, correct the coordinates or loop, and run again. Keep fail-safe enabled. |
onScreen() returns false |
The coordinate is outside the current screen bounds. | Use pyautogui.size() to inspect dimensions and choose an in-bounds point. |
| Clicks work locally but not in the deployment session | Platform permissions, display-server/session type, or desktop security policy differs. | Check the operating system’s input permissions and confirm that the script runs in a graphical session with access to the intended display. |
| A normal window works but an elevated one does not | The target runs at a different privilege level. | Review the platform’s policy for cross-privilege input and run the automation under an appropriate, consistent account only when permitted. |
Start every diagnosis with the same five checks: print the pointer position, print screen dimensions, verify onScreen(x, y), add a visible move or pause, and confirm the correct window has focus. These checks distinguish a bad coordinate from an environment problem before you change the script.
Fixed coordinates versus other targeting approaches
Fixed coordinates are simple and fast when the screen layout is controlled. They become fragile when users move windows, change display scaling, switch monitors, or run the code on a different machine. A more state-aware design can inspect the current interface before deciding where to click, but the official click and coordinate references do not establish a benchmark proving that one targeting strategy is universally more reliable.
- Use fixed coordinates for a known kiosk, test fixture, or repeatable desktop layout.
- Validate bounds with
onScreen()whenever coordinates come from configuration or calculations. - Make timing explicit with
PAUSEand short move durations when the application changes state. - Log positions and dimensions so a failure can be reproduced instead of guessed at.
- Keep an emergency stop by leaving fail-safe mode enabled.
Or skip the browser setup:
If your real goal is to capture a webpage rather than control a desktop window, ScreenshotNeo makes one HTTP request and returns a PNG, JPEG, WebP, or PDF. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for authentication and options. Equivalent Python and Node.js requests are:
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Options include full-page captures with lazy images loaded, CSS-selector element captures, dark mode, device presets, arbitrary viewports, retina scale, PDF paper and margin controls, custom CSS and JavaScript, pre-capture clicks, hidden selectors, selector/delay/network-idle waits, request and resource blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, configurable cache TTL, signed image links, asynchronous jobs with signed webhooks, bulk capture for up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs also work for easier migration.
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; higher plans are Growth ($15 for 15,000), Pro ($39 for 60,000), Scale ($99 for 250,000), and Business ($249 for 1,000,000). Yearly billing provides two months free, and every feature is available on every plan. Create a free ScreenshotNeo account to start with the 1,000 monthly screenshots.
Quick Recap
Practical checklist
- Install PyAutoGUI in the same Python environment that runs the script.
- Set
FAILSAFE = Trueand a smallPAUSE. - Confirm the coordinate origin and measure the target on the primary screen.
- Print
position()andsize()while diagnosing. - Reject invalid coordinates with
onScreen(). - Use
button,clicks, andintervalto express the intended gesture. - Check focus, scaling, permissions, display session, and privilege level when a correct-looking coordinate still fails.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

