A Python utility for automated image detection and clicking
Project description
OptimiseWait
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.pngextension. If a list is provided, they are searched in order.dontwait(bool, defaultFalse): IfTrue, the function checks only once and returns immediately. IfFalse, it loops until an image is found.specreg(tuple, defaultNone): A specific region to search in(x, y, width, height). Searching a smaller region is much faster.clicks(int or list[int], default1): The number of times to click.- int: Applies that many clicks to any image found (e.g.,
clicks=0finds but doesn't click). - list[int]: Assigns clicks by index corresponding to
filename. If the list is shorter, remaining images default to1click.
- int: Applies that many clicks to any image found (e.g.,
xoff(int or list[int], default0): Horizontal pixel offset for the click, relative to the image's center.yoff(int or list[int], default0): 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 whendontwait=False.clickdelay(float, optional): The delay in seconds between multiple clicks whenclicksis 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 mainfilename. 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], default1): The number of clicks to perform on a foundinterrupterimage. Behaves like theclicksparameter, accepting an integer for all interrupters or a list to specify clicks for each.interrupter_once(bool, defaultTrue): IfTrue, each interrupter image will only be clicked the first time it appears. IfFalse, it will be clicked every time it's detected in the waiting loop.
Return Value
Returns a dictionary containing the search result:
found(bool):Trueif an image was found, otherwiseFalse.image(str | None): The filename of the found image, orNone.location(Point | Box | None): The PyAutoGUI location object (PointorBox) of the found image.
Notes
- All image files must be in
.pngformat. - Image searching uses a 90% confidence level by default.
- If
clicksis a single integer, it applies to any image that is found. - If
xoff/yofflists are shorter than thefilenamelist, remaining images default to an offset of0. - Click offsets are always calculated from the center of the found image, even when using
specreg.
Dependencies
- PyAutoGUI >= 0.9.53
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optimisewait-0.6.1.tar.gz.
File metadata
- Download URL: optimisewait-0.6.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e230d048fc9eb802f000b124cb1a4ae375e678185e81043683e00cadbf6b04c5
|
|
| MD5 |
3af91e3ef23470cd48d7379ca0226375
|
|
| BLAKE2b-256 |
3f65aedcb0e117751aceb13993dc666b8846f0c69f882b77e857b19236b348d0
|
File details
Details for the file optimisewait-0.6.1-py3-none-any.whl.
File metadata
- Download URL: optimisewait-0.6.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d5ee808be71ff69e9e908c61e9aa9bf5d21ea9b485403e7534be2a316edb58c
|
|
| MD5 |
301612fbec25cd05d4dc3623ebcb5771
|
|
| BLAKE2b-256 |
fdc79deb3e7a83a9ef5241df81a75fd1c47c088b102ac221251089e59cc755e8
|