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:
- pyqt5_example.py: An example of using
wingrabin the main thread of a PyQt5 application. - pyqt5_example_run_in_sub_thread.py: An example of using
wingrabin the sub thread of a PyQt5 application. - tkinter_example.py: An example of using
wingrabin a Tkinter application. - run_in_sub_thread.py: An example of using
wingrabin a sub thread of a console application.
Metadata
Release files for WinGrab 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| wingrab-0.0.2.tar.gz | 7.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| WinGrab-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.7 kB
Release files / wingrab-0.0.2.tar.gz
| Download URL | wingrab-0.0.2.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
383177b663f15903c9188cd0dbb3f5d7514b315cf2a5b4035779557db7d84daf
|
|
BLAKE2b-256 checksum How to use checksums |
0e6a2bdabce8e5f9171b6c9c35a7843a3ce959bac9969ec7729e0041d578bbf2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.7
|
Release files / WinGrab-0.0.2-py3-none-any.whl
| Download URL | WinGrab-0.0.2-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0f517bb8fa17cf9fe147bfb62a5fbb657fc703d3f85edc99fe4ef72df7d29ff
|
|
BLAKE2b-256 checksum How to use checksums |
4425a40ef8490616cdbd801d84f6f363d19046eea046d7780eb1cbe6d5403b38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.7
|