Skip to content

StayActive v4.0.0

Latest

Choose a tag to compare

@virtualox virtualox released this 23 May 10:52
· 2 commits to main since this release
8c46f16

Changelog

[4.0.0] - 2026-05-23

Added

  • KeepAwake Mode: New -KeepAwake / -KeepDisplay parameters call SetThreadExecutionState so Windows itself keeps the system (and optionally the display) awake. Ideal for presentations, long downloads, and remote sessions. The execution-state flag is cleared on exit.
  • Idle Guard for Nudge Mode: New -OnlyWhenIdle and -IdleSeconds parameters use GetLastInputInfo to skip a cycle if the user has been active recently, so the cursor no longer jumps while you are typing or clicking.
  • INPUTS / OUTPUTS / LINK Help Sections: Comment-based help now documents the lack of pipeline support and links to the GitHub repo, so Get-Help .\StayActive.ps1 -Online works.

Changed

  • Modern Win32 Input API: Mouse input migrated from the superseded mouse_event to SendInput. Signed dx/dy removes the uint two's-complement workaround that the old code needed to express negative motion.
  • Output Streams: Status output now uses Write-Information (the Information stream) and Write-Progress instead of Write-Host, so output can be redirected, suppressed, or captured like any other PowerShell stream.
  • Help System: Replaced the custom -Help switch with comment-based help; use Get-Help .\StayActive.ps1 -Full instead.
  • Synopsis: Tightened to a single sentence in the conventional third-person present tense, matching built-in cmdlet style.

Improved

  • Idempotent Interop: Add-Type is now guarded so re-running the script in the same PowerShell session no longer fails on duplicate CLR types. Native types live in their own StayActive namespace to avoid global collisions.
  • Native Error Surfacing: GetCursorPos and GetLastInputInfo return values are checked and any Win32 error is surfaced via GetLastWin32Error instead of silently returning a zeroed POINT.
  • Cleaner Verbose Detection: -Verbose is now detected via $PSBoundParameters.ContainsKey('Verbose'), so a globally set $VerbosePreference no longer triggers the script's per-cycle countdown unintentionally.
  • Verbose Countdown: Now uses Write-Progress with -SecondsRemaining instead of writing a line per second.

Security

  • Code Signing: Script is digitally signed with Extended Validation (EV) Code Signing Certificate.
  • Constrained Language Mode Detection: Script exits early with an actionable message if PowerShell is running under AppLocker / WDAC ConstrainedLanguage mode, instead of failing partway through with a confusing Add-Type error.
  • Platform Guard: On PowerShell 7, the script checks $IsWindows and exits with a pointer to caffeinate (macOS) or systemd-inhibit (Linux) instead of crashing on user32.dll.

Breaking Changes

  • -Help Removed: Use Get-Help .\StayActive.ps1 -Full or -Online instead. Anyone scripting .\StayActive.ps1 -Help needs to update.
  • Output Streams: Status no longer goes to the host directly via Write-Host. Scripts that captured stdout will need to use -InformationAction Continue or the 6> redirection operator.
  • Parameter Sets: -MoveInterval, -SmallMove, -OnlyWhenIdle, -IdleSeconds belong to the Nudge set; -KeepAwake, -KeepDisplay belong to the KeepAwake set. Mixing them produces a parameter-set error.

Migration Guide

From v3.1.0 to v4.0.0:

  • Replace .\StayActive.ps1 -Help with Get-Help .\StayActive.ps1 -Full
  • If you piped or redirected the script's output, switch from stdout capture to 6> (Information stream) or pass -InformationAction SilentlyContinue to mute it
  • For "keep the machine awake" use cases (presentations, downloads), prefer the new -KeepAwake over the default Nudge mode
  • For "stay marked active in Teams" use cases, keep using the default (Nudge), and consider adding -OnlyWhenIdle so the cursor only moves when you have actually walked away

Notes

  • Nudge mode (the original behaviour) remains the default; passing no parameters works exactly as before
  • KeepAwake is a power-management hint and will not keep Teams or similar presence-aware apps from marking you away — use Nudge for that
  • Requires FullLanguage mode; the script exits with a clear message under Constrained Language Mode
  • Tested on Windows PowerShell 5.1 and PowerShell 7+