https://github.com/nstechbytes/detect-desktop
Detect when Windows desktop is in foreground.
https://github.com/nstechbytes/detect-desktop
Last synced: 4 months ago
JSON representation
Detect when Windows desktop is in foreground.
- Host: GitHub
- URL: https://github.com/nstechbytes/detect-desktop
- Owner: NSTechBytes
- License: mit
- Created: 2025-05-24T03:57:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-28T01:46:12.000Z (about 1 year ago)
- Last Synced: 2025-09-16T00:19:41.025Z (9 months ago)
- Language: C++
- Size: 54.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ฅ๏ธ desktop-detector
A small Windows utility and Node.js wrapper that detects when the desktop becomes the foreground window (i.e., when all applications are minimized).
This version improves detection by distinguishing between a true "Show Desktop" (triggered via Win+D or the taskbar button) and a simple click on the desktop:
* **Show Desktop** is recognized when:
* Any window minimize-start event occurs within a 500-millisecond window before desktop activation (meaning a "burst" of one or more minimization events).
* It is triggered via the "Show Desktop" button or the Win+D hotkey.
* A **plain click** on the desktop is ignored as a "Show Desktop" event and logs only a simple "shown" state.
---
## โ๏ธ Features
* Detects when the Windows desktop is shown or hidden (based on focus).
* Distinguishes "Show Desktop" (via key/button) from ordinary clicks.
* Exposes a clean JavaScript API for use in Node.js.
* Optional `--quiet` and `--log` CLI flags for flexible output.
---
## ๐ฆ Installation
```bash
npm install desktop-detector
```
Or clone it:
```bash
git clone https://github.com/nstechbytes/desktop-detector.git
cd desktop-detector
npm install
```
---
## ๐ Usage
### In Node.js:
```js
const { startDesktopDetector } = require('desktop-detector');
// Start monitoring
const proc = startDesktopDetector({
quiet: false, // show console output
log: true // also log to `detect-desktop.log`
});
// Optional: stop after 10 seconds
setTimeout(() => {
proc.kill();
console.log("Stopped detector.");
}, 10000);
```
---
## ๐งฐ CLI Options
You can also run the binary directly:
```bash
./bin/detect-desktop.exe [--quiet] [--log] [--help]
```
| Flag | Description |
| --------- | ----------------------------------------- |
| `--quiet` | Suppresses console output |
| `--log` | Logs output to `detect-desktop.log` |
| `--help` | Displays usage information |
---
## ๐งช Example Output
```
[2025-05-24 16:00:00] Initial state: Desktop is BACKGROUND
[2025-05-24 16:00:00] Listening for Show Desktop; press Ctrl+C to exit.
[2025-05-24 16:01:10] *** Desktop is now FOREGROUND (Show Desktop)
[2025-05-24 16:01:12] *** Desktop is now BACKGROUND (apps restored via desktopMode)
[2025-05-24 16:02:00] *** Desktop is now FOREGROUND (shown)
```
---
## ๐ License
MIT ยฉ nstechbytes