A Python utility for automated image detection and clicking
Project description
OptimiseWait
A Python utility function for 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 default path for all subsequent optimiseWait calls
set_autopath(r'D:\Images')
# Optional: Set an alternative path for fallback image search
set_altpath(r'D:\Images\Alt')
# Basic usage - wait for image and click
result = optimiseWait('button') # Looks for button.png in D:\Images, then D:\Images\Alt if not found
# Returns {'found': True, 'image': 'button'} if found
Usage Examples
# Override default path for specific call
result = optimiseWait('button', autopath=r'D:\OtherImages')
# Specify both main and alternative paths for specific call
result = optimiseWait('button', autopath=r'D:\Images', altpath=r'D:\Images\Alt')
# Don't wait for image (check if image exists)
result = optimiseWait('button', dontwait=True)
# Returns {'found': False, 'image': None} if not found
# Multiple click options
optimiseWait('button', clicks=2) # Double click
optimiseWait('button', clicks=3) # Triple click
optimiseWait('button', clicks=0) # No click, just wait for image
# Multiple images to search for
result = optimiseWait(['button', 'alt1', 'alt2']) # Will click first image found
# Returns {'found': True, 'image': 'alt1'} if alt1 was found first
# Different clicks per image
optimiseWait(['button', 'alt1', 'alt2'], clicks=[2, 3, 1]) # Different clicks per image
# Offset clicking - single value
optimiseWait('button', xoff=10, yoff=20) # Click 10px right, 20px down from center
# Offset clicking - multiple values for different images
optimiseWait(['button1', 'button2'], xoff=[10, 20], yoff=[5, 15]) # Different offsets per image
optimiseWait(['button1', 'button2', 'button3'], xoff=[10, 20]) # Remaining offsets default to 0
# Scroll to find an image (only effective if dontwait=False)
result = optimiseWait('image_far_down', scrolltofind='pagedown') # Scrolls pagedown until found
result = optimiseWait('image_far_up', scrolltofind='pageup') # Scrolls pageup until found
# scrolltofind has no effect if dontwait=True:
result = optimiseWait('button', dontwait=True, scrolltofind='pagedown') # Will not scroll
Functions
set_autopath(path)
Sets the default path for image files that will be used by all subsequent optimiseWait calls.
path: String. Directory path where image files are located.
set_altpath(path)
Sets the default alternative path for image files. If an image is not found in the main path, it will be searched for in this alternative path.
path: String. Directory path for alternative image files location.
optimiseWait(filename, ...)
Main function for image detection and clicking.
Parameters
filename: String or list of strings. Image filename(s) without .png extensiondontwait: Boolean (defaultFalse). IfTrue, don't wait for image to appear; checks once and returns.specreg: Tuple (defaultNone). Specific region to search in (x, y, width, height).clicks: Integer or list (default1). Number of clicks per image (0 = no click, 1 = single, 2 = double, 3 = triple).xoff: Integer or list (default0). X offset from the found image's location for clicking. Can be different for each image.yoff: Integer or list (default0). Y offset from the found image's location for clicking. Can be different for each image.autopath: String (optional). Directory containing image files. If not provided, uses path set byset_autopath().altpath: String (optional). Alternative directory for image files. If an image is not found inautopath, it will be searched for here. If not provided, uses path set byset_altpath().scrolltofind: String (defaultNone). If set to'pageup'or'pagedown', the function will simulate Page Up or Page Down key presses respectively if an image is not immediately found. This is only active whendontwait=False.
Return Value
Returns a dictionary with:
found: Boolean indicating if any image was found.image: String name of the found image, orNoneif no image was found.
Notes
- All image files should be PNG format.
- Images are searched with 90% confidence level.
- Function will wait indefinitely until an image is found (unless
dontwait=True). - When
scrolltofindis active (e.g.,'pagedown') anddontwait=False, the function will scroll and re-check indefinitely if the image isn't found, with a short pause after each scroll. - When using multiple images, it will try each in order until one is found.
- Images are first searched in the main path (
autopath), then in the alternative path (altpath) if provided and not found in the main path. - If
clicksis a single integer, it applies to the first found image (others default to 1 click). - If
clicksis a list shorter thanfilenamelist, remaining images default to 1 click. - If
xoff/yoffare single integers, the same offset applies to all images. - If
xoff/yoffare lists shorter thanfilenamelist, remaining offsets default to 0. - Click offsets are calculated from the center of the found image if
specregisNone. Ifspecregis used,pyautogui.locateOnScreenreturns top-left coordinates, and offsets are applied to these. - Default image paths can be set once using
set_autopath()andset_altpath()and reused across multiple calls.
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.4.0.tar.gz.
File metadata
- Download URL: optimisewait-0.4.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b318176501ca5efd5b6b963e11c0279ffe662fa2160fe81e84640c7747efa9a
|
|
| MD5 |
9a6865b8d2fadc433cdd19cadbbad97a
|
|
| BLAKE2b-256 |
2a3d6bc9abfc3799c5abcd6ce3e510bbdb37c60519f3642acec25d974fba9390
|
File details
Details for the file optimisewait-0.4.0-py3-none-any.whl.
File metadata
- Download URL: optimisewait-0.4.0-py3-none-any.whl
- Upload date:
- Size: 5.8 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 |
8b88e614d49f6744c7922989c711930de53cb23e22ef77c39ec285afbec83aa1
|
|
| MD5 |
a1d6884437ef174684a999a947ec16eb
|
|
| BLAKE2b-256 |
2d5221eb8fc703d965fab0710a11b3374d6ce443e1064beaf7c52341d9593d0d
|