Skip to main content

OptimiseWait

PyPI version License: MIT

A Python utility function for robust, automated image detection and clicking using PyAutoGUI.

Installation

# Install latest stable version from PyPI
pip install optimisewait

# Install latest pre-release (beta) version from PyPI
pip install --pre optimisewait

# Or install from source (gets the latest code from the repository)
git clone https://github.com/AMAMazing/optimisewait.git
cd optimisewait
pip install .

Quick Start

from optimisewait import optimiseWait, set_autopath, set_altpath

# Set a global default path for all subsequent optimiseWait calls
set_autopath(r'D:\Images')

# Optional: Set a global fallback path if images aren't in the primary path
set_altpath(r'D:\Images\Alt')

# Basic usage: waits for 'button.png' and clicks it once.
# Searches in D:\Images first, then D:\Images\Alt.
result = optimiseWait('button')
# Returns {'found': True, 'image': 'button', 'location': Point(x=123, y=456)}

Usage Examples

# Override default path for a specific call
result = optimiseWait('button', autopath=r'D:\OtherImages')

# Don't wait; check once if the image exists and return immediately
result = optimiseWait('button', dontwait=True)
# Returns {'found': False, ...} if not found on the first check

# Multiple click options
optimiseWait('button', clicks=2)  # Double-clicks the button
optimiseWait('button', clicks=0)  # Finds the button but does not click

# Search for multiple images; acts on the first one found
result = optimiseWait(['save_button', 'confirm_button', 'ok_button'])

# Different clicks per image using a list
# Clicks 'save' 2x, 'confirm' 0x, and 'ok' defaults to 1x.
optimiseWait(['save', 'confirm', 'ok'], clicks=[2, 0])

# Offset clicking from the center of the image
optimiseWait('button', xoff=10, yoff=-5)  # Clicks 10px right and 5px up

# Different offsets for different images
optimiseWait(['user_icon', 'pass_icon'], xoff=[10, 20], yoff=[5, 15])

# Scroll to find an image (when dontwait=False)
# Scrolls pagedown repeatedly until 'image_far_down.png' is found
result = optimiseWait('image_far_down', scrolltofind='pagedown')

# Handle intermittent pop-ups while waiting
# Waits for 'process_complete.png' to appear.
# If 'accept_cookies.png' or 'close_ad.png' appears during the wait,
# it will click them once and then continue waiting for the main image.
optimiseWait(
    'process_complete',
    interrupter=['accept_cookies', 'close_ad'],
    interrupter_once=True
)

Functions

set_autopath(path)

Sets the global default path for image files. This path will be used by all subsequent optimiseWait calls unless overridden by the autopath parameter.

  • path (str): Directory path where your primary image files are located.

set_altpath(path)

Sets the global default alternative path. If an image isn't found in the main path, this fallback path will be searched.

  • path (str): Directory path for alternative image files.

optimiseWait(filename, ...)

The main function for finding an image on screen and interacting with it.

Parameters

  • filename (str or list[str]): Image filename(s) without the .png extension. If a list is provided, they are searched in order.
  • dontwait (bool, default False): If True, the function checks only once and returns immediately. If False, it loops until an image is found.
  • specreg (tuple, default None): A specific region to search in (x, y, width, height). Searching a smaller region is much faster.
  • clicks (int or list[int], default 1): The number of times to click.
    • int: Applies that many clicks to any image found (e.g., clicks=0 finds but doesn't click).
    • list[int]: Assigns clicks by index corresponding to filename. If the list is shorter, remaining images default to 1 click.
  • xoff (int or list[int], default 0): Horizontal pixel offset for the click, relative to the image's center.
  • yoff (int or list[int], default 0): Vertical pixel offset for the click, relative to the image's center.
  • autopath (str, optional): Overrides the global default path for this specific call.
  • altpath (str, optional): Overrides the global alternative path for this specific call.
  • scrolltofind (str, optional): Can be 'pageup' or 'pagedown'. If an image isn't found, this key will be pressed before re-scanning. Only active when dontwait=False.
  • clickdelay (float, optional): The delay in seconds between multiple clicks when clicks is greater than 1. Defaults to 0.1.
  • interrupter (str or list[str], optional): An image (or list of images) to check for while waiting for the main filename. If an interrupter image is found, it is clicked, and the function continues waiting. This is useful for handling pop-ups or intermittent UI elements that might appear during a long wait.
  • interrupterclicks (int or list[int], default 1): The number of clicks to perform on a found interrupter image. Behaves like the clicks parameter, accepting an integer for all interrupters or a list to specify clicks for each.
  • interrupter_once (bool, default True): If True, each interrupter image will only be clicked the first time it appears. If False, it will be clicked every time it's detected in the waiting loop.

Return Value

Returns a dictionary containing the search result:

  • found (bool): True if an image was found, otherwise False.
  • image (str | None): The filename of the found image, or None.
  • location (Point | Box | None): The PyAutoGUI location object (Point or Box) of the found image.

Notes

  • All image files must be in .png format.
  • Image searching uses a 90% confidence level by default.
  • If clicks is a single integer, it applies to any image that is found.
  • If xoff/yoff lists are shorter than the filename list, remaining images default to an offset of 0.
  • Click offsets are always calculated from the center of the found image, even when using specreg.

Dependencies

  • PyAutoGUI >= 0.9.53

License

MIT License

Metadata

Release files for optimisewait 0.9.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optimisewait 0.9.3
File Size Uploaded Provenance Actions
optimisewait-0.9.3.tar.gz 19.7 kB Without provenance Details for optimisewait-0.9.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for optimisewait 0.9.3
File Interpreter ABI Platform Actions
optimisewait-0.9.3-py3-none-any.whl Python 3 none any Details for optimisewait-0.9.3-py3-none-any.whl

Total release size: 37.1 kB

Release files / optimisewait-0.9.3.tar.gz

Download URL optimisewait-0.9.3.tar.gz
Size 19.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b5e92855dee32ffdbb7570add449e10bebe388849b2586e8e37ba134c3208511
BLAKE2b-256 checksum
How to use checksums
f4c9387d268441e664622199c2720aff57e80440b6976347d73c903da2ad02cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / optimisewait-0.9.3-py3-none-any.whl

Download URL optimisewait-0.9.3-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc02512effe3b6af222341548b39141df2bb69d9900e1f3384fdbe5b740be58a
BLAKE2b-256 checksum
How to use checksums
ef0ce1492162f4eb9f4a535b30ec2c10b1fe0f7ad60d266ed0408826c6e73156
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for optimisewait 0.9.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page