Skip to main content

bgautogui

bgautogui is a small Windows-only Python package for background mouse automation using Win32 window messages.

It provides a PyAutoGUI-like API for sending click and scroll messages to windows under a screen coordinate, without moving the physical mouse cursor.

Status: alpha. This package is useful for local desktop automation and testing, but some applications may ignore posted Win32 messages.

Features

  • Windows background click without moving the real cursor.
  • Screen-coordinate based API: click(x, y), scroll(clicks, x, y).
  • Multiple target modes: first N window candidates, specific candidate indices, or specific Win32 class names.
  • Optional visual click ring for debugging coordinates.
  • No required runtime dependencies outside the Python standard library.
  • Optional vision extra for screenshot/image-detection workflows.

Installation

After publishing to PyPI:

pip install bgautogui

With optional vision dependencies:

pip install "bgautogui[vision]"

For local editable development:

pip install -e .

or with uv:

uv pip install -e .

Quick start

from bgautogui import BackgroundAutoGUI

bg = BackgroundAutoGUI()

# Click at the current cursor position.
bg.click()

# Click at a fixed screen coordinate.
bg.click(1500, 300)

# Scroll down at a fixed screen coordinate.
bg.scroll(-3, 1500, 300)

By default, BackgroundAutoGUI() sends each logical click to the first 4 window candidates under the coordinate.

bg = BackgroundAutoGUI(max_targets=4)

Target modes

# Default: first 4 candidates
bg = BackgroundAutoGUI()

# Only candidate 1
bg = BackgroundAutoGUI(max_targets=1)

# Specific candidate indices, 1-based
bg = BackgroundAutoGUI(target_indices=[1, 3])

# Specific Win32 class names
bg = BackgroundAutoGUI(target_classes=["IHWindowClass"])

Examples that may be useful depending on the application:

# Remote Desktop Connection input window, depending on environment.
BackgroundAutoGUI(target_classes=["IHWindowClass"])

# Chrome/Edge web content, depending on environment.
BackgroundAutoGUI(target_classes=["Chrome_RenderWidgetHostHWND"])

# Excel worksheet area, depending on environment.
BackgroundAutoGUI(target_classes=["EXCEL7"])

Visual click ring

Visual effects are disabled by default. Enable a small ring at the clicked coordinate:

bg = BackgroundAutoGUI(show_click_effect=True)
bg.click()

Enable it for a single click:

bg = BackgroundAutoGUI()
bg.click(show_click_effect=True)

Show the ring without sending any click message:

bg.showClickEffect()
bg.showClickEffect(1500, 300)

Customize the ring:

bg = BackgroundAutoGUI(
    show_click_effect=True,
    click_effect_radius=22,
    click_effect_duration=0.4,
    click_effect_color="#00AEEF",
    click_effect_width=3,
)

API overview

bg.position()
bg.size()
bg.center()
bg.virtual_screen()

bg.click()
bg.doubleClick()
bg.rightClick()
bg.middleClick()
bg.mouseDown()
bg.mouseUp()
bg.scroll()

bg.candidateWindowInfo()
bg.targetWindowInfo()
bg.windowInfo()
bg.probe()

bg.isPressed()
bg.is_mouse_button_held()

bg.set_click_effect()
bg.showClickEffect()

Inspecting candidates

from bgautogui import BackgroundAutoGUI

bg = BackgroundAutoGUI()

for info in bg.candidateWindowInfo():
    print(info.index, info.hwnd, info.class_name, info.title)

Debug by clicking each candidate one by one:

bg.probe(delay=2)

Low-interference configuration

from bgautogui import BackgroundAutoGUI

bg = BackgroundAutoGUI(
    target_indices=[1],
    show_click_effect=False,
    verbose=False,
    skip_when_mouse_button_held=True,
    hover_delay=0,
    mouse_down_up_delay=0.01,
)

Notes and limitations

bgautogui uses posted Win32 messages. A successful PostMessageW call does not guarantee that the target application will perform the UI action.

It may not work with:

  • games and anti-cheat protected applications;
  • some UWP/WinUI/custom-rendered applications;
  • minimized windows;
  • applications running as administrator when Python is not elevated;
  • applications that ignore posted Win32 mouse messages.

bgautogui intentionally does not provide moveTo() or reliable background drag support. It is designed to avoid moving the physical cursor.

Responsible use

This package is intended for legitimate local desktop automation and testing. Do not use it to bypass access controls, anti-cheat systems, user consent, or software terms of service.

License

MIT License. See LICENSE.

Metadata

Release files for bgautogui 0.1.0

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

Source distribution (sdist)

Source distribution for bgautogui 0.1.0
File Size Uploaded Provenance Actions
bgautogui-0.1.0.tar.gz 14.1 kB Without provenance Details for bgautogui-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 26.3 kB

Release files / bgautogui-0.1.0.tar.gz

Download URL bgautogui-0.1.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
92b227f230b646bae21c13f0c80c9d010a0b9af8e6931cd6e18059d742814a51
BLAKE2b-256 checksum
How to use checksums
c6166a6af46ce6bab2264c7ab4b2812336c04b2798621600970258fb783aeeb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / bgautogui-0.1.0-py3-none-any.whl

Download URL bgautogui-0.1.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2d93f4e60f5889261f576d777f09906692155a6df83972f194ca4fdc5132daf1
BLAKE2b-256 checksum
How to use checksums
7101af64d8f129a8433af89562d3ce501243190806e17c54c0e90e0f9d59114c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Security for bgautogui 0.1.0

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

This release

0.1.0 This release

2 release files No provenance

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