Skip to main content

Gui automation

Simple python library useful for automating tasks using images. It can run on Windows background applications.

It uses OpenCV and PyAutoGui. Made with Python 3.7.

Simple example:

import cv2
from gui_automation import GuiAuto

image_path = "win10key.png"
ga = GuiAuto()
if ga.detect(cv2.imread(image_path), 0.8):
    ga.click()

It searches windows 10 key image in the screen with at least a 80% of coincidence. If it is found it gets clicked (it opens windows 10 start menu).

The core class is GuiAuto:

Wraps detection and controlling of the GUI. By default it will use normal image detection and foreground app automation.

  • Parameters
detector: detector instance. Default is TMDetector()
handler:  handler instance. Default is ForegroundHandler()
  • Methods
detect: returns Spot instance if it finds the tpl in the image.
move: it moves the cursor to given coordinates or the center of the found image withing the screen.
click: Clicks the left buttons the quantity specified in parameter click(default 1) in given coordinates or the center.
hold: same as click but instead of clicking X times, it holds the click a given quantity of seconds received in time parameter.
drag: Drags from one point to another. For more information read this function documentation.
Detector:

Searches an image inside another image using template match from OpenCV. Classes with default parameters:

TMDetector(method=SQDIFF, thresh=False)
Applies the normal detection.

MultiscaledTMDetector(method=SQDIFF, thresh=False, reduce_sc=0.2, magnify_sc=2.0, cant_sc=40)
Applies detection multiples times while resizing the image. Parameters specify how image is resized.
  • Parameters
method: template method to use. Could be SQDIFF, CCOEFF or CCORR.
thresh: boolean that specifies if binary threshold filter must be used for detection.
reduce_sc: how much the image is reduced.
magnify_sc how much the image is enlarged.
cant_sc= how many resizing will be applied.
Handler:

Interacts with the app or environment to be automated. Performs clicks, drags among others; and also obtains the screen of the app/environment on an image format.

ForegroundHandler()
Normal handler that takes screenshot and simulates mouse action normally.

BackgroundHandlerWin32(app_name, *args)
Handler that works in not vieawable/background applications. It requires an application/window name, and it's possible to pass as arguments a names hierarchy of the UI elements of the application.
Works only for Windows.
Spot:

Wraps all position/coordinates calculations for the found image.

  • Methods:
upper_left_position()
upper_right_position()
bottom_left_position()
bottom_right_position()
center_position()
custom_position(x_multiplier, x_modifier, y_multiplier, y_modifier)
For this last one, check its documentation to understand parameters.
Image loader:

Little module to help load images from a directory. Loads all images of a folder given in param path, and assign them to a dictionary in this way: name=>image name would be the filename without the extension. image would be the numpy array with the image data loaded with OpenCV. Path: relative or absolute path where the images are. Must finish with '/'. It returns a dictionary with the names of the images as keys, and the images themselves as values. Returns False if any error.

  • Eg:
from gui_automation import GuiAuto, load_images
from time import sleep

buttons = load_images("images/buttons/")

ga = GuiAuto()
while not ga.detect(buttons['start'], 0.8).detect():
    ga.click()
sleep(2)
if ga.detect(buttons['accept'], 0.8):
    print("Found accept button")

In this case we load all images in "images/buttons/" folder and the wait until start button is found. After that, it waits 2 seconds and then it tries to find accept button.

Another example:
image_path = "win10keyresized.PNG"
ga = GuiAuto(detector=MultiscaledTMDetector())
spot = ga.detect(cv2.imread(image_path), 0.8)
if spot:
    ga.click(coords=spot.bottom_right(), clicks=3 )

In this case we have a similar win10key image to our original located on our rendered screen. So using MultiscaledTMDetector fixes our problem resizing the screen multiple times. If it is detected, it clicks the bottom right of the image found three times.

Metadata

Release files for gui-automation 3

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

Built distribution (wheel)

Table of built distributions (wheels) for gui-automation 3
File Interpreter ABI Platform
gui_automation-3-py3-none-any.whl Python 3 none any Details

Release files / gui_automation-3-py3-none-any.whl

Download URL gui_automation-3-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a06e8164bfd3f9fc8bf9fd821f5d1bc2a0f8a3496073e4a340028682dcbb5f4d
BLAKE2b-256 checksum
How to use checksums
711963c1fff5f6504d0f7fe9acc6865b393bc7935d0434abfc8c87cb716657f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Security for gui-automation 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.

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