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 mouse cursor, implemented in Python.

wingrab is implemented in the Python language, supports running directly and integrating into Python code, and currently only supports Windows.

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.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

WinGrab-0.0.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file wingrab-0.0.2.tar.gz.

File metadata

  • Download URL: wingrab-0.0.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.7

File hashes

Hashes for wingrab-0.0.2.tar.gz
Algorithm Hash digest
SHA256 383177b663f15903c9188cd0dbb3f5d7514b315cf2a5b4035779557db7d84daf
MD5 fcfd806cad739909b696b47a75931120
BLAKE2b-256 0e6a2bdabce8e5f9171b6c9c35a7843a3ce959bac9969ec7729e0041d578bbf2

See more details on using hashes here.

File details

Details for the file WinGrab-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: WinGrab-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.7

File hashes

Hashes for WinGrab-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e0f517bb8fa17cf9fe147bfb62a5fbb657fc703d3f85edc99fe4ef72df7d29ff
MD5 a26fb469f400873887da0175bfd1a31a
BLAKE2b-256 4425a40ef8490616cdbd801d84f6f363d19046eea046d7780eb1cbe6d5403b38

See more details on using hashes here.

Supported by

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