Skip to main content

appshwnd

This module provides utilities for finding and manipulating windows in Windows OS. It includes functions for finding windows based on various attributes, getting information about visible and invisible windows, and making window names unique (e.g. With FFmpeg, you can record a window, but you have to pass the title of the Window which causes problems if there are duplicates. )

pip install appshwnd

### Tested against Windows 10 / Python 3.10 / Anaconda

Functions

FUNCTIONS
    find_window_and_make_best_window_unique(searchdict: dict, timeout: float | int = 5, make_unique: bool = True, *args, **kwargs)
            Search for the window that matches the given criteria dictionary and makes its window title unique (if desired).
        Args:
            searchdict (dict): The dictionary that contains the search criteria for the window.
            timeout (float or int): The time in seconds to wait for making the window unique. Defaults to 5.
            make_unique (bool): Whether to make the window unique or not. Defaults to True.
            *args: Passed to re.search .
            **kwargs: Passed to re.search
        Returns:
            A tuple of best windows, best window, hwnd, start window text, updated window text, and revert name function.
    
    get_invisible_and_visible_windows()
            Get information about both visible and invisible windows.
        Args:
            None
        Returns:
            A list of WindowInfo objects for both visible and invisible windows.
    
    get_invisible_windows()
            Get information about invisible windows only.
        Args:
            None
        Returns:
            A list of WindowInfo objects for invisible windows only.
    
    get_visible_windows()
            Get information about visible windows only.
        Args:
            None
        Returns:
            A list of WindowInfo objects for visible windows only.
    
    time(...)
        time() -> floating point number
        
        Return the current time in seconds since the Epoch.
        Fractions of a second may be present if the system clock provides them.



# A dictionary that contains all possible search criteria for finding a window. 
# You can pass as many attributes as you want. The window with the most matches wins. 
searchdict = {
    "pid": 1004,
    "pid_re": "^1.*",
    "title": "IME",
    "title_re": "IM?E",
    "windowtext": "Default IME",
    "windowtext_re": r"Default\s*IME",
    "hwnd": 197666,
    "hwnd_re": r"\d+",
    "length": 12,
    "length_re": "[0-9]+",
    "tid": 6636,
    "tid_re": r"6\d+36",
    "status": "invisible",
    "status_re": "(?:in)?visible",
    "coords_client": (0, 0, 0, 0),
    "coords_client_re": r"\([\d,\s]+\)",
    "dim_client": (0, 0),
    "dim_client_re": "(1?0, 0)",
    "coords_win": (0, 0, 0, 0),
    "coords_win_re": r"\)$",
    "dim_win": (0, 0),
    "dim_win_re": "(1?0, 0)",
    "class_name": "IME",
    "class_name_re": "I?ME$",
    "path": "C:\\Windows\\ImmersiveControlPanel\\SystemSettings.exe",
    "path_re": "SystemSettings.exe",
}

from appshwnd import ( find_window_and_make_best_window_unique,
 get_invisible_and_visible_windows,
 get_invisible_windows,
 get_visible_windows,
 get_window_infos,)
 
 
# Find the window without changing the window title 
(
    bestwindows,  # most matches = first place
    bestwindow,  # WindowInfo object
    hwnd,  # 132762
    startwindowtext,  # 'Default IME'
    updatedwindowtext,  # 'Default IME' (no difference, because of make_unique=False)
    revertnamefunction,  # restore the original name
) = find_window_and_make_best_window_unique(
    searchdict, timeout=5, make_unique=False, flags=re.I
)

# Example search for Notepad 


get_visible_windows()
....
WindowInfo(pid=8896, title='Notepad', windowtext='*Untitled - Notepad', hwnd=2034552, length=20, tid=2772, status='visible', coords_client=(0, 877, 0, 675), dim_client=(877, 675), coords_win=(745, 1638, 324, 1058), dim_win=(893, 734), class_name='Notepad', path='C:\\Windows\\System32\\notepad.exe'),
....
WindowInfo(pid=16852, title='Notepad', windowtext='*Untitled - Notepad', hwnd=657206, length=20, tid=16876, status='visible', coords_client=(0, 877, 0, 675), dim_client=(877, 675), coords_win=(475, 1368, 219, 953), dim_win=(893, 734), class_name='Notepad', path='C:\\Windows\\System32\\notepad.exe')]
....


searchdict = {
    "title": "Notepad",
    "windowtext_re": r"\*+",
    'path_re': '.*notepad.exe.*'
}

# Find the window and make it unique
(
    bestwindows,  # most matches = first place
    bestwindow,  # WindowInfo object
    hwnd,  # window handle
    startwindowtext,  # current window text
    updatedwindowtext,  # updated window text
    revertnamefunction,  # function to restore the original window text
) = find_window_and_make_best_window_unique(
    searchdict, timeout=5, make_unique=True, flags=re.I
)

# Example of restoring the original window text
startwindowtext  # '*Untitled - Notepad'
updatedwindowtext  # '*Untitled - Notepad ' (notice the space at the end - this window title is now unique)
revertnamefunction()  # Restore the old name
startwindowtext  # '*Untitled - Notepad'
updatedwindowtext  # '*Untitled - Notepad'

An example with FFmpeg (to make sure that you are recording the right window)
1) Make the window title unique 
2) Start FFmpeg in a subprocess (Popen)
3) After 2 seconds, you can change the name back: revertnamefunction()

Metadata

Release files for appshwnd 0.11

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

Source distribution (sdist)

Source distribution for appshwnd 0.11
File Size Uploaded Provenance Actions
appshwnd-0.11.tar.gz 6.1 kB Without provenance Details for appshwnd-0.11.tar.gz

Built distribution (wheel)

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

Total release size: 15.4 kB

Release files / appshwnd-0.11.tar.gz

Download URL appshwnd-0.11.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7b6d2d30eb4c3a0f667c57627ec91498731fba0365b674303c9839be2164bb4d
BLAKE2b-256 checksum
How to use checksums
a68dc4f25bd07781bc1a30b45282eea05bd4b7f335d872fc2b1b28bba0c92fb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Release files / appshwnd-0.11-py3-none-any.whl

Download URL appshwnd-0.11-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4af988db2aba7cf4afc83adb02941563254ce7333a10ab078d63f0bb43d428a2
BLAKE2b-256 checksum
How to use checksums
d2f6a12ccd8654406b334f1c737db1f01caa8feeb5d656ec86a397c9ced063ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.10

Security for appshwnd 0.11

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.11 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