Skip to main content

WinGrab: A simple tool to get the PID of the window under the cursor.

Project description

WinGrab

A simple tool to get the PID of the window under the cursor.

Installation

From pip

pip install wingrab

From source code

Download the wingrab.py and cursor.cur files and place them in your project directory, ensuring the cursor.cur file is in the same location as wingrab.py.

Usage

Run directly in CLI

Ensure the wingrab package is installed via pip, You can then run it directly in the CLI using:

py-wingrab

or

py-wingrab grab

You can run it together with some powershell commands like Get-Process:

Get-Process -Id $(py-wingrab)

If wingrab crashes, and the mouse cursor has changed to a cross, run the cleanup command to try to restore the mouse cursor.

py-wingrab cleanup

Integrate into your Python code

It is very simple to integrate wingrab into your Python code, you just need to call the grab function in the wingrab package.

from wingrab import wingrab

pid = wingrab.grab()

The grab function returns the PID of the window under the cursor as an integer.

Note that the grab will block the current thread until the user clicks the left mouse button, so if you want to use it in a GUI application, you had better call the grab function in a sub thread. (See examples below)

Note: wingrab can be used in both the main thread and the sub threads, but if you want to use it in a sub thread, make sure to call wingrab.grab() in the main thread first.

To restore the global mouse cursor to the default when wingrab crashes, invoke the cleanup function.

from wingrab import wingrab

wingrab.cleanup()

Examples

examples directory contains several examples which demonstrate usage and integration methods. You can run them directly after installing the package:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

WinGrab-0.0.1a4.tar.gz (7.3 kB view hashes)

Uploaded Source

Built Distribution

WinGrab-0.0.1a4-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page