This document covers the shared library (AllScripts/SharedHelpers.ahk), the debounce pattern it provides as a reusable template, the bottom-right badge system, the local-path leak prevention setup, the Windows Task Scheduler boot architecture, DRM Video Streaming Mode, the master tray menu, the Sunshine/Moonlight display topology and watchdog lifecycle, and the Simple Sticky Notes multi-resolution layout engine.
Read this before adding a new hotkey or feature that needs any of these.
Every script that needs one of these includes it with an explicit %A_ScriptDir% prefix:
#Include %A_ScriptDir%\SharedHelpers.ahkNever a bare #Include SharedHelpers.ahk.
- In AutoHotkey, a bare relative
#Includepath resolves against the process's initial working directory at load-time preprocessing, not necessarily the including script's own folder. - This only "worked" historically for a bare
#Include *i LocalPaths.ahkbecause of exactly howStartupScript.ahkhappened to launch each script. - Launch a script any other way (a manual reload from a shell with a different working directory, for instance) and a bare include can silently fail to resolve.
SharedHelpers.ahk also runs standalone as its own StartupScript.ahk tray entry, for quick Edit access (same reason LocalPaths.ahk does below).
- This uses a narrow exception to its own "no top-level directives" rule: a single
Persistent()call at the top. #Persistentwas a v1-only directive; in v2 it silently hangs the process at load time instead of erroring (confirmed empirically, seeOfficial Documentation/AHK-v1-to-v2-Migration-Notes.md§18.1), andPersistent()is the runtime function call that replaces it.- That's a pure lifecycle call rather than meaningful executable code, so it's a no-op for every
#Includeing script (they all already stay alive via their own hotkeys/loops). - It only actually matters for this standalone run.
- The explicit
%A_ScriptDir%\form is immune to this regardless of how the script is launched.
Important gotcha: include it before any hotkey definition.
- AHK's auto-execute section ends at the first hotkey/hotstring definition,
Return, orExitencountered during a top-to-bottom load-time scan. - That scan skips over function bodies entirely (recognized and deferred, never executed inline).
- v2 has no plain (non-hotkey) label at all in the v1 sense: every
SetTimer/OnMessagetarget here (RemoveBottomRightBadge,RemoveTimedToolTip, etc.) is a real zero-parameter function, which the language requires and which auto-execute scanning correctly skips over. - If you add a new
SetTimertarget to this file, it must be a function reference: v2 has no label-basedSetTimerdispatch to fall back on.
-
AcquireNamedMutex(mutexName, timeoutMs)/ReleaseNamedMutex(hMutex): cross-process mutual exclusion via a real Win32 named mutex, not a file-existence convention.- A plain lock file can be left permanently stuck if the owning process crashes mid-critical-section. A named mutex cannot: Windows marks it "abandoned" and the next waiter picks it up cleanly.
- The mutex name is a parameter, not hardcoded, specifically so this is reusable for any future resource needing cross-process exclusion, not just one.
- Pick a distinct, descriptive name per logical resource (e.g.
"SkillsVaultLock_AHK_v1"); every caller sharing that exact string, across however many separate processes, contends on the same kernel object.
-
DebounceArmTimer/DebounceTryBeginCommit/DebounceEndCommit: the "settle after N ms of quiet, then act once" pattern. See the worked example below. -
ShowBottomRightBadge(msg, bgColorHex, displayMs := 0)/HideBottomRightBadge()/RemoveBottomRightBadge()- A colored toast, bottom-right corner, singleton: a second call while one is showing updates its color/text in place, never destroys/recreates or stacks. The window is created once and reused, so there is no visible gap between transitions.
displayMs := 0means "stay until the next Show/Hide call"; pass an explicit value for anything that should auto-dismiss on its own.HideBottomRightBadge()dismisses immediately without a replacement badge: use it when real work has finished and there's nothing new worth telling the user. (See the Skills Vault commit phase inBasicTasks.ahk, which hides the "applying" badge on completion instead of showing a third, redundant "done" badge that would just repeat what was already shown at press time.)- See the badge section below for the DPI subtlety this encodes.
-
ShowSkillsStatusBadge(msg): thin color-mapping wrapper overShowBottomRightBadge, specific to the Skills Vault feature (maps a[LOCKED]/[UNLOCKED]/[AUTO]/error-shaped message to its color, shown for 3000ms).- Shared by
BasicTasks.ahk(manual toggle's fast-phase requested-state badge) andBackgroundAutomations.ahk(WatchSkillsLock's post-commit confirmation) so the color convention is defined exactly once.
- Shared by
-
ShowTimedToolTip(msg, displayMs)/RemoveTimedToolTip(): a nativeToolTipauto-dismissed after N ms.- Use this for simple near-cursor feedback; use
ShowBottomRightBadgewhen you want color/fixed-position control.
- Use this for simple near-cursor feedback; use
-
PublishTrayMenuManifest(itemsArray)/HandleRemoteTrayMenuTrigger: publishes a script's custom tray-menu items soStartupScript.ahk's master submenu can mirror them generically.- Call once per script, near the top of its auto-execute section:
PublishTrayMenuManifest([ ["Display Label 1", "TrayLabel1"] , ["-"] , ["Display Label 2", "TrayLabel2"] ])
- Each script gets its own manifest file (
%A_Temp%\ahk_traymenu_<ScriptName>.txt, keyed by that script's own filename), so sharing this one function across multiple processes is safe: there's no cross-process state beyond the convention of one manifest file per script. - Separator Support: An entry of
["-"]or a string"-"serializes to"-|"in the manifest. WhenStartupScript.ahkreads the manifest, any item whose first token is"-"(or empty) calls a bare.Add()on that script's per-PIDMenuobject to insert a native Win32 horizontal separator line, grouping custom items cleanly. - If a script stops publishing items it previously did (a feature moved elsewhere, say), delete its stale manifest file once by hand.
StartupScript.ahk'sHandleRemoteTrayMenuTriggerguard (aMap.Has()check against the fleet's registered handler names, replacing legacy v1IsLabel) keeps a leftover manifest from raising an error dialog, but won't clean up the dead entry on its own.
Tray menu shape, built by
StartupScript.ahk'sMenuBuild():- Each managed script's own submenu is deliberately minimal:
View Key History/Edit/Restart/Exit, plus that script's own published items. Pause and Suspend are not per-script. StartupScript.ahkexposes one global "Suspend Hotkeys" tray item (and matchingWin+ScrollLockhotkey) that cascades a real Suspend-Hotkeys toggle to every managed script at once, leaving each script's own background timers/watchers running. That's why Suspend was chosen over Pause, which would freeze those too.- This replaces AutoHotkey's own native Suspend Hotkeys/Pause Script/Exit tray items (which only ever acted on the master script's own hotkeys, not the fleet) rather than sitting alongside them. So there is exactly one Suspend action and one Exit action, not two of each.
StartupScript.ahk's own 4 hotkeys need no exemption mechanism at all (no legacySuspend, Permit, no#SuspendExempt).SuspendAllToggleonly ever posts to the managed child scripts, never to this master script's own window, so none of its hotkeys can ever actually become suspended.- "Restart" kills a script and relaunches it fresh without moving it to the Load submenu (unlike Exit). Useful when just one script needs a clean restart without a full fleet reload.
-
ShowDRMStatusBadge(msg): thin color-mapping wrapper overShowBottomRightBadge, specific to the DRM Video Streaming Mode feature (maps[ACTIVE]to deep green#1A6E3C, and[OFF]to dark slate grey#3A3D40, shown for 3000ms). -
ShowBottomRightBadge(msg, bgHex, durationMs): the core drawing function. Creates a borderless, captionless, non-activating (+E0x08000000/WS_EX_NOACTIVATE) GUI window with large white bold text on the requested background color. Dynamically queries monitor work area dimensions, places the GUI in the lower-right corner (offset 20px from right, 60px from bottom to clear taskbars), applies 210/255 transparency, and schedules auto-dismiss via a non-blockingSetTimer. If a badge is already active, resets the timer to avoid overlap.
| Color Name | Hex Code | Semantic Meaning |
|---|---|---|
| Deep Red | 8B0000 |
Critical failure / hard stop / kill action |
| Dark Red | 6E1A1A |
Feature turned OFF (mute, stream close) |
| Deep Green | 1A6E3C |
Feature turned ON (unmute, stream start) |
| Blue | 1A4E6E |
Info / cycle state change |
| Slate Grey | 3A3D40 |
Passive status / dismiss |
| Amber | 6E5A00 |
Work in progress ("applying..."), not an error |
-
Chromium browser lifecycle helpers (
GetTargetBrowsersForDRM,GetBrowserHardwareAcceleration,SetBrowserHardwareAcceleration,CloseBrowserGracefully,LaunchBrowserInstance)- Cross-cutting utility functions providing graceful session-preserving shutdown, preference parsing, and headless/GPU flag manipulation for Chromium-based browsers (Brave and Google Chrome).
- Used by
BasicTasks.ahkfor the DRM Video Streaming Mode toggle.
-
Core Audio Microphone helpers (
ToggleMicrophoneMute,GetMicrophoneMute,SetMicrophoneMute,UpdateMicrophoneTrayIcon)- Native Windows Core Audio WASAPI COM interfaces (
IMMDeviceEnumeratorandIAudioEndpointVolume) called directly via Win32DllCall. - Replaces legacy mixer and external dependencies (
nircmd.exe, PowerToys VCM). Executes in under 5ms without spawning external processes. - Automatically targets both
eConsole(0) andeCommunications(2) capture endpoints so Discord, Zoom, Teams, and browser calls are all muted in sync. - Integrates with
ShowBottomRightBadgefor instant DPI-scaled on-screen HUD toast notifications (deep red#8B1A1Afor Muted, deep green#1A6E3Cfor Unmuted). - Drives a dynamic system tray indicator: when unmuted, the tray icon is completely hidden (
A_IconHidden := true) for zero clutter. When muted, a dedicated high-contrast white microphone icon with a vivid neon-red diagonal slash (AutoHotkey Companion Files\mic_muted.ico) appears in the notification area (A_IconHidden := false,A_IconTipset to the persistent hover text). - Left-clicking the muted tray icon immediately unmutes the microphone and dismisses the icon.
- A lightweight 1500ms background watcher (
WatchMicrophoneMuteStateinBasicTasks.ahk) quietly detects external hardware/system mute changes and keeps the tray icon synchronized without firing disruptive toasts. StartupScript.ahk'sTrayIconRemoveexplicitly exemptsBasicTasksso mouseover events over the notification area do not wipe out the active mute icon.
- Native Windows Core Audio WASAPI COM interfaces (
-
RunSilentPowerShell(scriptPath, args := "")andRunSilentProcess(targetExe, args := "")- Launches PowerShell scripts or console binaries with zero visible window on Windows 11.
- Prefers
run_silent.exe(a C# GUI subsystem launcher built withCREATE_NO_WINDOW = 0x08000000andUseShellExecute = false). - Completely prevents the Windows Console Subsystem (
conhost.exeand Windows Terminal) from allocating or flashing a top-level console window onto the desktop. - Used for Simple Sticky Notes geometry repositioning (
apply_ssn_layout.ps1), mouse speed synchronization (set_normal.ps1,set_fast.ps1), ADB tablet intent dispatches, and WSL ext4 disk management.
MountExt4Ssd/UnmountExt4Ssd do not live here: the ext4 SSD feature (hotkeys, auto-mount watcher, tray items, and these two functions) is fully self-contained in AllScripts/Ext4SsdManager.ahk, matching the single-feature-script convention Brightness.ahk/ClosePrograms.ahk already use.
They only ever lived in this shared file because two other generic scripts happened to both need them, not because the feature is genuinely cross-cutting the way the debounce pattern or badge system are.
The problem this solves: a hotkey whose real work is slow (in this repo's case, an icacls sweep across 14 folders taking ~2.3-3.5 seconds) needs instant visual feedback on every press.
But it should only actually do that slow work once the user stops pressing: a rapid burst of presses should show a toast every time but commit only the last one.
Each feature owns its own state as three plain globals: a pending-value variable, a busy flag, and an interval, passed into the shared functions by name/&var.
Nothing in SharedHelpers.ahk stores any feature-specific state itself.
global g_MyFeatureDebounceMs := 2000 ; 2000ms is the default this codebase
; uses everywhere the pattern appears:
; keep new features consistent unless
; you have a specific reason not to.
global g_MyFeaturePendingValue := ""
global g_MyFeatureCommitBusy := false
; Fast phase: the actual hotkey/tray target. Never blocks.
MyFeatureFastPhase() {
global g_MyFeaturePendingValue, g_MyFeatureDebounceMs
; ... cycle/update g_MyFeaturePendingValue however your feature needs ...
; ... show instant feedback, e.g. ShowBottomRightBadge(...) ...
DebounceArmTimer(MyFeatureCommit, g_MyFeatureDebounceMs)
}
; Commit phase: an ordinary zero-parameter function, reached only via the timer armed above.
; Legacy v1's original shape used a label here (real SetTimer/Gosub targets in v1 could be either), but v2's
; SetTimer requires a real function reference: there is no remaining reason for a commit phase to ever
; be a label (see `Official Documentation/AHK-v1-to-v2-Migration-Notes.md` §11 for the full history of this specific change).
MyFeatureCommit() {
global g_MyFeaturePendingValue, g_MyFeatureCommitBusy, g_MyFeatureDebounceMs
if !DebounceTryBeginCommit(&g_MyFeatureCommitBusy, MyFeatureCommit, g_MyFeatureDebounceMs)
return
snapshotValue := g_MyFeaturePendingValue
; ... do the real (slow) work using snapshotValue ...
DebounceEndCommit(&g_MyFeaturePendingValue, snapshotValue, &g_MyFeatureCommitBusy, MyFeatureCommit, g_MyFeatureDebounceMs)
}Why this is correct, precisely:
DebounceArmTimeruses AHK's own documentedSetTimer"Reset" behavior: a negative period runs once after N ms, and callingSetTimeragain on an already-pending target cancels that countdown and starts a fresh one rather than stacking a second pending firing. So only the last press in any rapid run ever reaches the commit label, and only once the interval elapses with zero further presses.DebounceTryBeginCommit's busy-guard is defense-in-depth: AHK's timer engine already guarantees at most one concurrently-running instance of a given timer's target, so this should never actually trigger in practice.DebounceEndCommit's reconciliation is the subtle but important part:- If a press lands while the commit is already running (not just within the debounce window, but seconds later while the real work is genuinely mid-flight), that intent can't safely cancel already-dispatched work, so it doesn't try.
- Instead, comparing the live pending value against a snapshot taken before the slow work started detects the newer press and re-arms one more time, so it gets applied immediately after, never silently dropped.
- Real commits can't be cancelled once started. If your feature's "real work" is an external process launch (like
RunWait), killing it partway through to honor a newer press risks leaving it in a half-applied state, worse than letting it finish and following up immediately after. Don't try to make commits interruptible; let the reconciliation tail handle catching up instead.
Why plain global variables plus &var by-reference parameters, not a bound-function/closure approach:
- AutoHotkey v2 uses
&varfor by-reference parameters (replacing legacy v1ByRef), used throughout the debounce helpers (DebounceTryBeginCommit,DebounceEndCommit) exactly as before. - Legacy v1 dynamic
%var%-labelGosubdispatch (used for old tray manifest handlers) has no v2 equivalent: v2 requires a real function reference wherever v1 accepted a label or a constructed label-name string. Every timer/dispatch target in this pattern is now an ordinary function reference registered in aMap(), not a string. - A
Func().Bind()closure-per-feature approach was considered and rejected: it would need rebuilding the bound object on every re-arm (an object-target timer is deleted after firing, unlike a function-reference timer which just goesOffand can be reused), for no benefit over the existing plain-globals-plus-&varshape every feature in this codebase already uses.
Colors follow a simple convention: pick from these when adding a new message, or extend ShowSkillsStatusBadge (a SharedHelpers.ahk wrapper over ShowBottomRightBadge that maps a [LOCKED]/[UNLOCKED]/[AUTO]/error message to its color automatically, shared by both BasicTasks.ahk's manual toggle and BackgroundAutomations.ahk's auto watcher) if you need new ones:
| Color | Hex | Meaning |
|---|---|---|
| Deep green | 1A6E3C |
Unlocked / open / permissive state |
| Deep red | 8B1A1A |
Locked / restricted state |
| Deep blue | 0D4F8B |
Automatic / focus-driven state |
| Amber | 6E5A00 |
Work in progress ("applying..."), not an error |
| Dark orange | 7A3B00 |
Error |
The DPI subtlety ShowBottomRightBadge encodes:
- Under Windows display scaling above 100%, AutoHotkey GUI coordinate space without
-DPIScaleis DPI-virtualized: a GUI's rendered size can be inflated by the DPI scale factor relative to what was requested, even thoughx/yposition values pass through unscaled. - The fix: the
Guiis created with-DPIScale, which maps every coordinate and dimension AHK sets or reads for that Gui 1:1 to physical screen pixels: the inflation problem is avoided at the root instead of being measured and corrected after the fact. - Because sizing is physical-pixel-exact, the badge can be sized directly from a live GDI
DrawTextW(DT_CALCRECT) measurement of the actual message text, taken fresh on every call, rather than created at a fixed nominal size and corrected afterward. This is also what makes the auto-sizing pill shape possible: badge width tracks the measured text width, falling back to a word-wrapped box only for messages too long to fit inline. GetToastTargetMonitor()re-resolves which monitor is under the cursor on every call, and the work area (MonitorGetWorkArea()) is recalculated every call too: together these keep the badge anchored to the monitor actually in use (and its exact bottom-right work-area corner) across a Sunshine/Moonlight display-topology switch, rather than to a monitor index that goes stale the moment the active display changes.- If you copy this pattern for a new kind of popup, keep
-DPIScaleplus a live text measurement on every call; don't fall back to a fixed nominal size with an after-the-fact position correction, which can't follow a monitor change or a message-length change without recomputing everything anyway.
Create once, update in place: no destroy/recreate:
- Destroying and rebuilding the whole
Guion every call (Destroy->Sleep-> rebuild) produces a visible blank gap between badge transitions. ShowBottomRightBadgeinstead creates the window once (guarded by astatic createdflag) and every later call just updatesbadgeGui.BackColor, updatesbadgeTextCtl.Text, and re-Shows if hidden: no destroy, no sleep, no rebuild, so transitions are instant.- Dismissal (both the timer-driven path and the explicit
HideBottomRightBadge()) usesbadgeGui.Hide(), neverDestroy, so the window stays alive and ready for the next instant update. - Keep this create-once/update-in-place shape for any similar popup; reintroducing Destroy/Sleep brings the visible gap back.
The legacy v1 Hwnd-vs-v GUI hang does not apply in v2:
- On legacy AHK v1.1, adding a text control inside a user-defined function using the
vvariable option could hang the thread. - v2 has no equivalent bug and no
Hwnd-vs-vdistinction:GuiObj.AddText(...)(and every other.Add*()method) always returns the realGuiControlobject directly, from any calling context, function or auto-execute alike (confirmed empirically, seeOfficial Documentation/AHK-v1-to-v2-Migration-Notes.md§8).ShowBottomRightBadgeinSharedHelpers.ahknow stores that returned control object directly in aglobaland calls.Text := newTexton it: no HWND indirection needed at all. - If you add a new Gui-based helper function to this file, just keep the object
.Add*()returns; there is nothing left to work around here.
This repo is public (Arora-Sir/AutoHotKey-Windows-Scripts). Three files hold real local machine paths and are gitignored, each with a tracked .example counterpart carrying generic placeholders:
AllScripts/LocalPaths.ahkAllScripts/PersonalKeywords.ahkAllScripts/PowerShell/ssd_config.json
Two independent layers guard against a real path leaking into a tracked file anyway:
.githooks/pre-commit(local, tracked, fully generic: derives this machine's username/computer name from the environment at commit time rather than hardcoding them, since hardcoding them into a tracked file would itself be the exact leak this prevents).- Hard-blocks committing any of the 3 real config files if ever force-staged.
- Hard-blocks any other staged file containing this machine's username, computer name, or a generic per-user Windows profile path pattern.
- Warns (non-blocking) if a real config file has grown a variable/key its tracked
.examplehasn't caught up to yet. - Activated via a local-only git config:
git config core.hooksPath .githooks(not itself tracked: a fresh clone needs to run this once).
.github/workflows/no-local-path-leak.yml: a server-side backstop, since the local hook alone is bypassable (--no-verify, or simply never configuringcore.hooksPath). Can only check the same generic per-user Windows profile path pattern, never this machine's specific values (a CI runner has no legitimate way to know them, and a tracked workflow file embedding them would defeat the purpose).
A local, gitignored CLAUDE.md at the repo root carries additional contributor/tooling notes specific to this machine (not tracked, so not reproduced here).
Not every shared state goes through SharedHelpers.ahk. AllScripts/SunshineDisplayWatchdog.ahk coordinates the Sunshine fast/normal mouse-speed state through plain marker files, since Sunshine's own prep-cmd hooks: AllScripts/PowerShell/Sunshine/set_fast.ps1 (do) / set_normal.ps1 (undo), run directly by Sunshine on stream start/end, independent of any AHK script: already owned this convention before the AHK-side manual toggle existed.
.fast_since: the marker's mere existence means "fast mode"; its content distinguishes why: empty means a real Sunshine session set it (set_fast.ps1),"manual"means the Win+Alt+P toggle did.sunshine_manual_switch.flag(in%A_Temp%, separate from.fast_since): a 20-second-bounded grace window armed by manual toggles.SunshineDisplayWatchdog.ahkskips its sunshine.log/Tailscale disconnect checks entirely while this flag is younger than 20s. Those checks answer "did the old session end," not "has the user had time to open Moonlight yet," and would otherwise revert a deliberate toggle before the user connects. Bounded rather than indefinite, so toggling to tablet mode and never streaming does not permanently disable the disconnect checks. See that file's ownMANUAL OVERRIDEcomments for the full reasoning..session_quit: written byset_normal.ps1only when Sunshine's ownundoprep-cmd hook fires (an explicit Moonlight quit), never by the watchdog. LetsSunshineDisplayWatchdog.ahkshort-circuit straight to a ~1.5s display restore instead of waiting out the normal multi-poll debounce/settle window that exists to avoid reacting to a transient back-gesture/app-switch.
SunshineDisplayWatchdog.ahk binds Win+Alt+P (#!p) to toggle between PC Screen Only and Tablet Only, and Win+Alt+Shift+P (#!+p) to toggle between Extend and Duplicate. Previously, alternate bindings (Ctrl+Shift+P and Win+Shift+P) were tested in an attempt to trigger the toggle remotely from the Galaxy Tab S10 Ultra during a Moonlight session without walking over to the PC:
- Android intercepts recognized modifier-key combos (Alt+Tab, the Windows key, Ctrl+S, etc.) at the OS level before any app (Moonlight included) ever sees them, redirecting to Android's own system actions instead. This is a documented, still-open limitation in Moonlight Android (see its GitHub issues #840 and #975), not something fixable from this repo's side.
- This applies to both a physical/case Bluetooth keyboard and the tablet's own on-screen Samsung Keyboard: the latter's own Ctrl+A/Ctrl+C-style "shortcuts" are local Android text-editing actions, not genuine key events that would traverse to a remote session at all.
- Alternate keybinds like
Ctrl+Shift+Palso collided with universal editor shortcuts (Command Palette in VS Code / Antigravity).Win+Shift+Pis dedicated to Bitwarden Vault (Password Manager) inPersonalKeywords.ahk, leavingWin+Alt+Pas the dedicated host display toggle. - The confirmed-working remote path remains touching the PC's tray items (PC Screen Only, Tablet Only, Extend Displays, Duplicate Displays under
SunshineDisplayWatchdog.ahk's dedicated tray menu) directly through the Moonlight stream, since that involves no keyboard at all.
The AutoHotkey fleet is launched on Windows boot via a dedicated scheduled task named "AHK Startup Script", managed by setup_startup_task.ps1 (with Explorer-friendly 1-click batch wrappers Install_Startup_Task.bat and Uninstall_Startup_Task.bat).
-
30-Second Logon Delay (
PT30S):- Task Scheduler is deliberately chosen over Windows Startup (
shell:startupor registryRunkeys) because of startup race conditions. - On modern Windows 10/11 installations, audio endpoints, network adapters (Tailscale/Wi-Fi), graphics drivers, and the Windows Explorer shell initialize concurrently across multiple worker threads at user logon.
- Launching the AHK fleet instantaneously on logon causes tray icons to fail to register with
Shell_NotifyIcon, display topology queries to return incomplete monitor arrays, and background network checks to throw spurious errors. - A 30-second delay (
PT30S) ensures the entire desktop subsystem has settled beforeStartupScript.exeexecutes.
- Task Scheduler is deliberately chosen over Windows Startup (
-
Elevated Task Creation vs. Standard User Execution (
RunLevel Limited):- Registering or modifying tasks in the Task Scheduler root (
\) requires Administrator privileges. Therefore,Install_Startup_Task.batandsetup_startup_task.ps1self-elevate via PowerShellStart-Process -Verb RunAsif executed un-elevated. - However, the task itself is registered with
Principal.RunLevel = Limitedunder the user's standard account ($env:USERNAME). - Running as a standard user is critical: running AHK elevated would trigger UAC confirmation prompts on every boot, isolate window messages (UIPI blocks un-elevated apps from sending messages to elevated windows), and alter file virtualization paths.
- Registering or modifying tasks in the Task Scheduler root (
-
Battery Resilience & Infinite Execution:
- Registered with
Settings.AllowStartIfOnBatteries = $trueandSettings.DontStopIfGoingOnBatteries = $true. - Windows Task Scheduler defaults to stopping background tasks when a laptop disconnects from AC power; these flags guarantee continuous background automation on laptops.
ExecutionTimeLimit = PT0S(zero timeout) prevents Windows from terminating the fleet after the default 3-day task limit.
- Registered with
-
Recompilation & Relaunch Integration:
build_startup_exe.ps1checks for the existence of"AHK Startup Script"in Task Scheduler.- When invoked with
-Relaunch(or when triggered via theStartupScriptsubmenu's "Recompile & Relaunch" item), it first stopsStartupScript.exeto release file locks, compiles a fresh binary viaAhk2Exe, and triggersschtasks /run /tn "AHK Startup Script"to restart the master process seamlessly in the user's active session without command prompt flashes. If the scheduled task is not registered on that machine, it gracefully falls back toStart-Process.
When streaming desktop video to a tablet (such as Samsung Galaxy Tab S10 Ultra) or handheld device via Moonlight and Sunshine, hardware-accelerated video playback on Chromium browsers (Brave, Google Chrome) results in a black video screen for DRM-protected content (Netflix, Amazon Prime Video, Disney+ Hotstar, Udemy, etc.).
-
The Root Cause:
- Protected media playback utilizes Windows Hardware DRM / Protected Media Path (PMP) surfaces within Chromium's GPU process.
- Desktop duplication APIs (Direct3D Desktop Duplication / DXGI) used by Sunshine and Moonlight cannot capture protected Direct3D surfaces while GPU compositing is active, outputting solid black frames for the video area while subtitles and browser UI remain visible.
-
The Architecture Solution (
BasicTasks.ahk+SharedHelpers.ahk):- Rather than switching monitor topologies or disabling system-wide virtual display drivers, the toggle operates strictly at the browser application level via
ToggleDRMStreamingMode():
- Target Browser Resolution: Detects whether Brave or Chrome is active. When actively on Brave or Chrome (via immediate focus, recent focus tracking across tray interactions, or topmost unminimized window in desktop Z-order), the toggle acts strictly on that particular browser instead of parallel-restarting both. If neither browser is active, it halts gracefully with a notification badge without disrupting background processes.
- Graceful Shutdown (
CloseBrowserGracefully): SendsWM_CLOSEto all top-level windows (WinClose("ahk_id " . this_id)). This allows Chromium to write open tabs, history, and active sessions to disk cleanly. Lingering background watcher processes are terminated to release file locks on Chromium profile files. - Atomic
Local StateModification (SetBrowserHardwareAcceleration): Reads Chromium's rootLocal StateJSON file in UTF-8. Atomically sets"hardware_acceleration_mode": {"enabled": false}(and updateshardware_acceleration_mode_previous). Writes to a.tmpfile and performs an atomic replace (FileMove(tmpPath, targetPath, 1)) to eliminate corruption risks. - Targeted Relaunch (
LaunchBrowserInstance): Relaunches the browser with:--disable-gpu: Disables the GPU process, forcing software rasterization for video presentation surfaces.--restore-last-session: Automatically restores all previously open tabs without requiring manual user intervention.--disable-session-crashed-bubble: Suppresses the "Restore pages? Chromium didn't shut down correctly" warning bubble.
- Status Badge & Tray Menu Sync: Displays
ShowDRMStatusBadge(...)with explicit[ON]/[OFF]indicators (e.g.[ON] Graphics Accel: Brave (Normal GPU Mode)) and updates the tray menu item label dynamically viaUpdateDRMTrayStatus(Graphics Accel: Brave (ON) / Chrome (OFF)). - Reversion: Clicking the toggle again reverses the JSON preference (
"enabled": true), closes the browser gracefully, and relaunches with normal GPU hardware acceleration restored.
- Rather than switching monitor topologies or disabling system-wide virtual display drivers, the toggle operates strictly at the browser application level via
StartupScript.ahk provides a centralized system tray interface for the entire script fleet, ensuring that multiple background scripts do not clutter the Windows notification area with redundant icons.
-
Unified Single Tray Icon:
- On startup and resolution changes,
TrayIconRemoveiterates through all child script processes and callsShell32\Shell_NotifyIconwithNIM_DELETEon their notification handles. - The master script keeps only its own single tray icon active. Mouseover (
WM_MOUSEMOVE0x200) proactively cleans up any ghost icons left by terminated child processes.
- On startup and resolution changes,
-
Click Action Dispatch (
AHK_NOTIFYICON):- Tray interactions are intercepted via
OnMessage(0x404, AHK_NOTIFYICON):- Left-Click (
WM_LBUTTONUP0x202) & Right-Click (WM_RBUTTONUP0x205): Both left-click and right-click open the master tray context menu (A_TrayMenu.Show()). - Hover Tooltip (
WM_MOUSEMOVE0x200): Displays a dynamic sorted list of all active scripts and cleans up any ghost tray icons.
- Left-Click (
- Tray interactions are intercepted via
-
Menu Hierarchy & Pinned Scripts:
- Pinned Scripts: Scripts listed in
PinnedScripts(BasicTasks,PersonalKeywords,SunshineDisplayWatchdog) are rendered directly at the top level of the master tray menu for immediate 1-click submenu access. - Additional Scripts Submenu: All remaining active background scripts (
BackgroundAutomations,Brightness,ClosePrograms,Ext4SsdManager,HotkeyHelp,LocalPaths,SharedHelpers,Watchdog) are cleanly consolidated into an expandable "Additional Scripts" submenu, preventing vertical menu overflow. - Child Submenu Structure: Each managed script submenu provides standard management actions (
View Key History,Edit,Restart,Exit), followed by a horizontal separator line and any custom items published by that script. - Global Actions: Positioned at the bottom of the master menu: "Suspend Hotkeys" (global cascade toggle) and "Exit". Fleet maintenance actions ("Reload All", "Recompile & Relaunch") are housed inside the "Additional Scripts -> StartupScript" submenu to keep the top-level tray menu concise.
- Pinned Scripts: Scripts listed in
This system orchestrates high-performance, low-latency remote desktop streaming from the host laptop to a Samsung Galaxy Tab S10 Ultra using Sunshine, Moonlight, and an HDMI dummy plug, managed entirely by SunshineDisplayWatchdog.ahk with a dynamic checkmark tray interface in StartupScript and direct hotkeys (Win+Alt+P and Win+Alt+Shift+P).
flowchart TD
subgraph Host ["Host Laptop (Acer Predator Helios 300)"]
Internal["DISPLAY1: Internal Panel (1920x1080 @ 144Hz, 16:9)"]
DummyPlug["DISPLAY4: HDMI Dummy Plug (2560x1600 @ 120Hz, 16:10)"]
end
subgraph Client ["Client Device (Samsung Galaxy Tab S10 Ultra)"]
TabletScreen["OLED Panel (2560x1600 Native, 16:10 Aspect Ratio)"]
end
subgraph Modes ["Display Topologies"]
PC_Only["PC Screen Only (Win+Alt+P): DISPLAY1 Active, DISPLAY4 Off, Mouse Speed 10"]
Tab_Only["Tablet Mode / Second Screen Only (Win+Alt+P): DISPLAY1 Off, DISPLAY4 Active, Mouse Speed 20"]
Extend["Extend Displays (Win+Alt+Shift+P): Laptop Main (DISPLAY1) + Tablet Extended (DISPLAY4), Mouse Speed 10"]
Duplicate["Duplicate Mode (Win+Alt+Shift+P): DISPLAY1 Cloned with DISPLAY4, Mouse Speed 20"]
end
DummyPlug -. Matches Aspect Ratio .-> TabletScreen
PC_Only --> Internal
Tab_Only --> DummyPlug
Extend --> Internal
Extend --> DummyPlug
Duplicate --> Internal
Duplicate --> DummyPlug
sequenceDiagram
autonumber
actor User as User (Tablet / Laptop)
participant Moonlight as Moonlight (Tab S10 Ultra)
participant Sunshine as Sunshine Server (Windows Service)
participant Watchdog as SunshineDisplayWatchdog.ahk (Interactive Session & Display Manager)
participant Win11 as Windows 11 Display Engine (DisplaySwitch & SetDisplayConfig)
Note over User,Win11: Phase 1: Initiation & Streaming
User->>Win11: Win+Alt+P or Tray Menu (Toggle Tablet Mode)
Win11-->>User: DisplaySwitch /external (DISPLAY4 2560x1600 Active, Laptop Screen OFF, mouse speed boosted to 20 and 20s manual grace window armed directly by the toggle itself)
User->>Moonlight: Open Desktop Stream
Moonlight->>Sunshine: Connect Stream (Tailscale 100.x.y.z)
Sunshine->>Sunshine: DXGI Desktop Duplication on DISPLAY4 (2560x1600 @ 60/120Hz)
Sunshine->>Watchdog: Log "CLIENT CONNECTED"
Watchdog->>Watchdog: Clears manual grace flag (mouse speed was already boosted at the manual toggle above; ForceFast only re-boosts here for a resumed session where the marker was absent)
Note over User,Win11: Phase 2: Disconnect vs. Transient Back Button Flap
User->>Moonlight: Press Android Back / Switch Tablet App / Screen Timeout
Moonlight->>Sunshine: Disconnect Session
Sunshine->>Watchdog: Log "CLIENT DISCONNECTED"
Sunshine->>Sunshine: Start Undo Cmd countdown (5s-20s exit timeout)
alt Explicit Quit (Sunshine's own undo hook fires)
Sunshine->>Watchdog: set_normal.ps1 (Sunshine's undo prep-cmd, not a Watchdog action) writes .session_quit
Watchdog->>Win11: Instant restore (~1.5s): bypasses the debounce/settle window below entirely
else Aggressive Immediate Trigger (< 3s)
Watchdog->>Win11: DisplaySwitch /internal (Switches back to DISPLAY1 1080p)
Win11-->>Watchdog: Internal Screen ON, DISPLAY4 Deactivated
Note over User,Win11: Hazard: User returns to Moonlight after 3 seconds
User->>Moonlight: Re-tap Desktop Stream
Moonlight->>Sunshine: Connect while Windows is on DISPLAY1 (1080p)
Sunshine->>Sunshine: DXGI tries to capture DISPLAY1, races display topology, or hangs in duplicate window!
else Reconnect within Settle Window (< 3s or Debounce Window)
User->>Moonlight: Re-tap Desktop Stream within settle grace
Moonlight->>Sunshine: Re-connect before Watchdog switches display
Sunshine->>Sunshine: DISPLAY4 still active at 2560x1600, stream resumes smoothly without hang!
end
Note over User,Win11: Phase 3: Hardware Lid-Open Safety Net
User->>Host: Physically lift laptop lid while streaming
Host->>Watchdog: WM_DISPLAYCHANGE (0x007E) triggered by DISPLAY1 wake
Watchdog->>Win11: DisplaySwitch /internal (Restores PC Screen Only, mouse speed 10 if monCount <= 1)
| State / Event | Trigger | Intended Outcome | Potential Hazard / Consequence | Design Mitigation |
|---|---|---|---|---|
| Manual Tablet Toggle | Win+Alt+P / Tray Menu |
Switches to DisplaySwitch.exe /external, mouse speed 20. |
Sunshine log tail still shows old CLIENT DISCONNECTED. |
20s manual grace window (sunshine_manual_switch.flag) prevents watchdog revert. |
| Manual Laptop Toggle | Win+Alt+P / Tray Menu |
Switches to DisplaySwitch.exe /internal, mouse speed 10 in 0 ms. |
Stale markers could cause speed sticking. | Win32 speed 10 assertion + clearing .fast_since. While stream is idle on topo == 1, watchdog enforces speed 10. |
| Extend / Duplicate Toggle | Win+Alt+Shift+P / Tray Menu |
Toggles between Extend (DisplaySwitch.exe /extend, speed 10) and Duplicate (DisplaySwitch.exe /clone, speed 20). |
Direct /extend from PC Only or Duplicate fails on hybrid dual-GPU systems because the discrete GPU display pipe is asleep or clone-locked. |
Closed-loop handshake: if coming from topo == 1 or topo == 2, SwitchToExtendMode switches to /external, dispatches ADB wake and connect intent to tablet Moonlight, waits for Sunshine CLIENT CONNECTED confirmation, and only then applies /extend. |
| Moonlight Connect | Moonlight app taps "Desktop" | Sunshine captures active display (default mirror on DISPLAY1 or headless DISPLAY4). |
Auto-switching display topology on connect races with Sunshine DXGI and hangs. | Connect-side display topology remains explicit; watchdog dynamically boosts mouse speed to 20 across PC Screen Only, Duplicate, and Tablet Only modes during active streaming. |
| Transient Disconnect | Android back gesture / app switch | Stream pauses. | Mouse speed stuck fast on laptop screen. | Watchdog restores mouse speed 10 on PC Screen Only, Duplicate, and Extend modes within 1.5s, without disrupting display topology. |
| Permanent Disconnect | User finishes work, closes Moonlight | Sunshine session ends; mouse speed 10 restored. | Speed remains 20 if disconnect missed. | Multi-signal detection: Sunshine undo hook (.session_quit), Sunshine log (CLIENT DISCONNECTED), Tailscale peer offline check, and 8h ceiling. |
| Explicit Quit | Sunshine's own undo prep-cmd hook fires (set_normal.ps1) |
.session_quit written, mouse speed restored in 1.5s. |
Delayed recovery. | Watchdog consumes .session_quit on the next tick, resets streaks, and updates tray status. |
| Lid Open While Streaming | User opens laptop lid | Immediate return to Laptop Mode (DisplaySwitch.exe /internal), mouse speed 10. |
Infinite loop if display change re-triggers lid handler, or breaking multi-monitor setups. | Guard 1 (4s manual toggle lock) + Guard 2 (only acts if monCount <= 1 && topo != 2 && topo != 4). |
| System Resume from Wake | Win32 WM_POWERBROADCAST (0x0218) |
Triple-wave recovery (500ms, 2000ms, 4000ms) restores laptop display mode and mouse speed 10 if second screen remained active. | Slow GPU bus re-enumeration after Modern Standby can drop single-shot display switches. | Triple-wave staggered timers guarantee GPU driver settles before final confirmation pass. |
| Workstation Session Unlock | Win32 WM_WTSSESSION_CHANGE (0x02B1, WTS_SESSION_UNLOCK wParam=8) |
Restores laptop display mode if second screen active; recycles keyboard hook. | User wakes laptop, unlocks with biometric/PIN while virtual display is still engaged, or keyboard hook hangs. | Immediate display state check on session unlock + keyboard hook refresh ensuring hotkeys respond. |
On hybrid dual-GPU laptops (Intel UHD Graphics driving DISPLAY1 and dedicated NVIDIA GeForce GTX 1650 Ti driving DISPLAY4), switching directly from PC Screen Only (topo == 1) or Duplicate Displays (topo == 2) to Extend Displays (DisplaySwitch.exe /extend) fails silently. Windows 11 requires an active video streaming consumer established on the secondary discrete GPU display pipe before it can extend the desktop across both adapters.
The automated handshake enforces a closed-loop sequence with mandatory stream teardown:
- Topology verification: The system queries
GetCurrentDisplayTopology(). If already in Second Screen Only (8) or Extend (4), it executesDisplaySwitch.exe /extenddirectly. - Surface activation and stream teardown: If starting from PC Screen Only or Duplicate mode, the system invokes
SwitchToTabletOnlyMode()(DisplaySwitch.exe /external). If an existing tablet streaming session was active, the display disconnects from the laptop first. This disconnect causes Sunshine to release the previous DirectX Desktop Duplication (DXGI) adapter capture context. - Log baseline marking: The watchdog records the current byte length of
sunshine.log(g_ExtendTargetLogSize) so historical connection markers are ignored. - Automated tablet wake and client launch: An ADB command dispatched over Tailscale wakes the Galaxy Tab S10 Ultra and launches Moonlight directly into the desktop stream via
com.limelight/.ShortcutTrampoline. - Connection handshake polling: A 500ms non-blocking timer (
SunshineDisplay_WaitTabletConnectForExtend) pollssunshine.logfor a freshCLIENT CONNECTEDrecord beyond the baseline marker. - Decoding surface stabilization: Once
CLIENT CONNECTEDis confirmed, the system waits 1000ms for tablet video decoding to stabilize. - Extend execution: The system invokes
DisplaySwitch.exe /extend, restores mouse speed to 10 (normal), applies the laptop Simple Sticky Notes layout, and displays the Extend badge. - Fail-safe timeout: If no connection is detected within 20 seconds, the handshake cancels and remains in Tablet Only mode with an informative notification badge.
This section documents the dual deterministic desktop positioning system for Simple Sticky Notes (ssn.exe), implemented in AllScripts/PowerShell/apply_ssn_layout.ps1 and wired into AllScripts/SharedHelpers.ahk and AllScripts/SunshineDisplayWatchdog.ahk.
The workstation alternates between two distinct physical display surfaces:
-
Host Laptop Screen (
DISPLAY1):- Physical Resolution:
$1920 \times 1080$ @ 144Hz (16:9 aspect ratio) - Windows DPI Scale: 125%
- Logical Workspace (DIP):
$1536 \times 864$
- Physical Resolution:
-
Tablet Screen via HDMI Dummy Plug (
DISPLAY4):- Physical Resolution:
$2560 \times 1600$ @ 120Hz (16:10 aspect ratio) - Windows DPI Scale: 175%
- Logical Workspace (DIP):
$1463 \times 914$
- Physical Resolution:
On the laptop, notes span across 4 columns ending flush at the right bezel:
- Column 0:
$X = 0, W = 240$ - Column 1:
$X = 728, W = 240$ (ends at 968px) - Column 2:
$X = 968, W = 300$ (ends at 1268px) - Column 3:
$X = 1268, W = 268$ (ends at 1536px)
When Windows switches to Tablet Mode (DisplaySwitch 4), Column 3 extends 73 pixels beyond the tablet screen edge (
Instead of dynamic runtime snapshots (which capture corrupted positions during transitions), the engine enforces two mathematically calculated deterministic layouts:
| Column | Dimensions ( |
Description | Laptop ( |
Tablet ( |
|---|---|---|---|---|
| Col 0 | Far Left Bottom Note | |||
| Col 1 | Top Small Note | |||
| Col 1 | Bottom Square Note | |||
| Col 2 | Top Medium Note | |||
| Col 2 | Middle Note | |||
| Col 2 | Bottom Medium Note | |||
| Col 3 | "Today" Expanded Note | |||
| Col 3 | Minimized Title Bars (x5) |
-
Laptop Column 3 Edge:
$1268 + 268 = 1536\text{px}$ (flush against laptop right boundary). -
Tablet Column 3 Edge:
$1190 + 268 = 1458\text{px}$ (safe 5px margin before 1463px tablet edge, zero cut-off).
The positioning engine is triggered automatically across all display transition pathways:
- Manual Hotkeys (
Win+Alt+PandWin+Alt+Shift+P):SwitchToTabletOnlyMode()andSwitchToLaptopOnlyMode()inSunshineDisplayWatchdog.ahk: Executes display switch and callsApplyTabletStickyNotesLayout(1500)orApplyLaptopStickyNotesLayout(1500).
- Duplicate & Extend Modes:
SwitchToDuplicateMode()andSwitchToExtendMode()inSunshineDisplayWatchdog.ahk: Re-applies primary display layout once DWM settles.
- Sunshine Watchdog Auto-Revert:
SunshineWatchdog_ForceNormal()inSunshineDisplayWatchdog.ahk: When Moonlight disconnects or session times out, reverts to laptop mode and callsApplyLaptopStickyNotesLayout(2000).
- Hardware Lid Reopen (
WM_DISPLAYCHANGE 0x007E):SunshineDisplay_WM_DISPLAYCHANGEinSunshineDisplayWatchdog.ahk: Catches physical lid reopening during stream and restores laptop layout.
- Fleet Startup / User Logon:
StartupScript.ahkauto-execute: Evaluates current screen width and applies the matching layout.
The script avoids AutoHotkey desktop isolation and DWM race conditions via:
- Thread Desktop Attachment: Uses
OpenDesktop("Default", ...)andSetThreadDesktopto access the interactive surface. - Process Thread Enumeration: Calls
EnumThreadWindowsacrossssn.exethreads rather thanEnumWindows. - Dimension Signature Matching: Matches windows by width and height rather than volatile HWNDs.
- Dual-Wave Locking: Performs an active polling loop (up to 6s at 300ms intervals) followed by a secondary
SetWindowPospass 1.2s later to defeat late DWM refreshes.
Architectural decisions in this fleet prioritize reliability, non-blocking responsiveness, and resilience against Windows OS quirks.
- Context: Heavy cross-process operations (such as
icaclspermission sweeps during Skills Vault toggles) require mutual exclusion across multiple independent scripts. - Alternative: Creating a lock file on disk (
%TEMP%\vault.lock). - Decision: Win32 named kernel mutex (
CreateMutex,WaitForSingleObject). - Rationale: If an AHK process crashes or is forcefully terminated mid-operation, a lock file remains orphaned on disk, permanently wedging future operations. The Windows kernel automatically marks a named mutex as abandoned when its owning thread terminates, allowing the next waiting process to acquire it cleanly.
- Context: The fleet must auto-start on user logon.
- Alternative: Placing shortcuts in the Windows startup folder (
shell:startup). - Decision: Windows Task Scheduler trigger with a 30-second logon delay (
PT30S) andRunLevel Limited. - Rationale: At user logon, Windows Explorer, graphics drivers, audio services, and network adapters (Tailscale/Wi-Fi) initialize concurrently across multiple CPU threads. Launching immediately causes race conditions, missing system tray icons, and failed IPC registrations. A 30-second delay guarantees the desktop shell has completely settled.
RunLevel Limitedunder the standard user account prevents boot UAC prompts while maintaining proper window message routing.
- Context: The fleet originally stayed on v1.1 specifically because
StartupScript.ahk's dynamic runtime tray-submenu reflection (Menu, SubMenu_%PID%, Add, addressed by a constructed name string per child process) appeared tied to v1-only mechanics, with no clear v2 equivalent and no functional benefit seen in rewriting a stable, heavily-integrated codebase. - What actually happened: the fleet was fully ported to AutoHotkey v2.0. The submenu-mirroring concern that originally blocked this was resolved by replacing name-string-addressed submenus with real per-PID
Menuobjects held in aMap()(g_ScriptMenusinStartupScript.ahk): v2 attaches a submenu by object reference, not by a constructed name string, so the original blocker simply does not apply to the v2-native approach. - Process: every script was ported and verified live (not just "loads clean") against its real, actually-invoked feature set. Roughly 30 genuine v1->v2 language-migration bugs were found this way and are documented in full in
Official Documentation/AHK-v1-to-v2-Migration-Notes.md: missingglobaldeclarations,DllCalloutput-parameter quirks,Gui.Show()'s argument-count change,FileDeletenow throwing on a missing target where v1 was silent, and more. A companion parity audit confirmed every hotkey, hotstring, function, and explanatory comment in v1 has a working v2 counterpart. - Result:
#Requires AutoHotkey v2.0across the entire fleet;build_startup_exe.ps1compiles againstAutoHotkey\v2\AutoHotkey64.exe. The two backup git tags (backup/pre-v2-migration,backup/original-refs-heads-master) and normal commit history remain the rollback path if a v1-only behavior is ever found to have no working v2 equivalent after all.
- Context: Providing a single kill-switch hotkey (
Win+ScrollLock) to disable productivity hotkeys during gaming or full-screen apps. - Alternative: Pausing all child scripts (
Pause(-1)). - Decision: Cascading hotkey suspension (
PostMessage(g_FleetControlMsg, 4, 0, ...)) while keeping script event loops running. - Rationale: Pausing a script freezes its underlying timers, watchdog threads, and window message handlers. Background watchdogs (such as
SunshineDisplayWatchdog.ahkandWatchSkillsLock) must continue monitoring system state even when typing shortcuts are suspended. Hotkey suspension disables keyboard hooks while leaving background automation fully operational.
- Context: Operations requiring slow disk or permission changes (such as the 2.3-3.5 second
icaclsfolder sweep). - Alternative: Executing the slow command on every hotkey press, or queuing sequential runs.
- Decision: Two-phase settle architecture (
DebounceArmTimerandDebounceTryBeginCommit). - Rationale: Every keypress provides instant user feedback by updating a colored HUD badge in place, but defers execution by resetting a 2000ms countdown timer. Rapid successive presses update state in memory without locking the desktop. The heavy system command executes exactly once after the user stops pressing.
- Context: Repositioning Simple Sticky Notes (
ssn.exe) when switching between laptop screen and headless tablet display. - Alternative: Capturing window coordinates dynamically before display transitions and restoring them afterward.
- Decision: Enforcing mathematically calculated pixel coordinates (
apply_ssn_layout.ps1) based on detected screen width. - Rationale: Dynamic coordinate snapshots captured during display mode switches frequently record corrupted, intermediate positions caused by DWM boundary clamping (the 73px width deficit between laptop 1536px and tablet 1463px). Hardcoded coordinate tables guarantee pixel-perfect placement flush against screen bezels on every switch.
- Context: Wireless ADB file transfer to mobile devices via Tailscale or local Wi-Fi.
- Alternative: Invoking
adb connect <ip>:5555directly. - Decision: Probing port 5555 with a .NET
TcpClientsocket using a 500ms timeout prior to invoking ADB. - Rationale: Native
adb connecthas a hardcoded 21.1-second timeout when an IP is offline. Probing the port via a raw TCP handshake detects unreachable endpoints in 500ms, enabling instant failover from Tailscale to local Wi-Fi without locking Windows Explorer.
- Context: Expanding short keywords into email addresses, website URLs, government IDs, and large multi-line AI reasoning prompt directives.
- Problem: When
:X*:hotstrings for URLs used clipboard pasting (PasteText()), typinglinpro.in Chromium address bars (Chrome/Brave) caused the URL to collapse into://and produce an invalid scheme navigation error. - Root Cause: AutoHotkey sends 7 backspaces to erase
linpro.. InPasteText(), dispatchingSendInput("^v")with 0 ms delay created a race condition: Chromium was still draining backspaces from the Windows input queue whenCtrl+Vlanded. Two backspaces drained before the paste, and the remaining 5 backspaces drained afterhttps://was pasted, deletinghttps(5 characters) and leaving only://. - Decision: Added a 50 ms backspace-drain settle delay (
Sleep(50)) insidePasteText()beforeSendInput("^v"):- URLs, Emails, and AI Prompts (
PasteText()):- Uses
ClipboardAll()backup, sets clipboard, waits viaClipWait(1), sleeps 50 ms to allow the target window's message loop to completely drain all backspaces, issuesSendInput("^v"), and waits 100 ms before restoring previous clipboard content. - Provides instant expansion (0 ms visual feel) across both browser Omnibox fields and rich text editors with zero character loss or scheme corruption.
- Uses
- Government IDs and Tax Numbers (
AadharNo.,PanNo.) via Native Keystrokes (:*:):- Indian banking, tax, and government KYC portals frequently enforce JavaScript paste blockers (
onpaste="return false;"). - Keystroke simulation bypasses paste restrictions;
Ctrl+Vclipboard pasting is actively rejected.
- Indian banking, tax, and government KYC portals frequently enforce JavaScript paste blockers (
- URLs, Emails, and AI Prompts (
- Context: In-file documentation comments, header shortcut summaries, and the two-column GUI built by
HotkeyHelp.ahk. - Problem: Historical scripts mixed multi-hyphen arrows (
-->forward and<--backward). The double-hyphen substring created friction with the zero double-hyphens documentation invariant and risked false positives in automated linters. Additionally, hotkeys defined without an inline semicolon comment (such as multi-line declarations$!F4::or taskbar wheel controlsWheelUp::Send("{Volume_Up}")) causedHotkeyHelp.ahkto display blank descriptions in the GUI because its parser searches specifically for::.*?;(.*). - Decision: Standardized all arrow symbols across the repository to single-hyphen notation without exceptions:
- Header & Block Comments (
->):- Format:
; Key -> Action(e.g.; Win+F -> Run Firefox). - Uses single-hyphen right arrow
->to represent causal triggers cleanly while completely eliminating ASCII double-hyphens.
- Format:
- Hotkey Help Inline Comments (
<-):- Format:
Key::Action ;{ <- Description(e.g.WheelUp::Send("{Volume_Up}") ;{ <- (Taskbar) Volume Up). HotkeyHelp.ahksplits output into two columns: Hotkey Name (padded to 25 characters on the left) and Description (on the right). The single-hyphen left arrow<-visually points back toward the hotkey name, preserving intuitive layout cues with zero double-hyphens.- Multi-line hotkeys and context-sensitive directives require an explicit inline comment on the hotkey declaration line so
RegExMatch(File_Line, "::.*?;(.*)", Match)captures the intended description.
- Format:
- Header & Block Comments (
- Context: Managing transitions between single-monitor laptop display (DISPLAY1), headless tablet streaming (DISPLAY4 dummy plug), and multi-monitor extended or duplicated desktop layouts.
- Problem: Previously, display switching was coupled into
BasicTasks.ahkwhile the mouse watchdog was in a separate script (SunshineMouseWatchdog.ahk). When switching back to PC Screen Only, the watchdog would frequently re-boost mouse speed to 20 because it saw active Sunshine log entries without checking the active display topology. In addition, when extending displays, the streaming client suffered because Windows 11 only shows system tray icons on the primary display. - Decision: Consolidated all display switching, multi-monitor topology, and watchdog logic into
SunshineDisplayWatchdog.ahk:- Second Screen Only Isolation (
IsSecondScreenOnly()):- Queries active monitors and display topology via
GetCurrentDisplayTopology()andMonitorGetCount(), returning true only if the internal laptop panel (DISPLAY1) is completely absent. - In Extend or Duplicate mode,
DISPLAY1remains attached and active, soIsSecondScreenOnly()reliably returns false.
- Queries active monitors and display topology via
- Active Display Topology Guard & Stream State Synchronization:
- Watchdog actively inspects display topology via
GetCurrentDisplayTopology()and tracks stream status viasunshine.log. - When streaming is active (
CLIENT CONNECTED), mouse speed 20 is enforced across default laptop mirror (topo == 1), duplicate (topo == 2), and tablet only (topo == 8). - When streaming is idle or disconnected, normal speed 10 is maintained on laptop and extended displays.
- Watchdog actively inspects display topology via
- Dedicated Sunshine Extended Display Profile:
- Configured
"Desktop (Extended Tab)"targeting\\.\DISPLAY4in Sunshineapps.json. - Enables streaming the extended canvas to the tablet while preserving the laptop screen as Primary Display with all taskbar notification icons intact.
- Configured
- Multi-Monitor Immunity for Watchdog and Lid Recovery:
- Watchdog and lid-open handlers guard restorations with
monCount <= 1. In Extend mode, multi-monitor layouts are never disrupted.
- Watchdog and lid-open handlers guard restorations with
- Second Screen Only Isolation (
- Context: Global microphone mute hotkey (
Win+Ctrl+Alt+M) with visual feedback on Windows 10 and 11. - Problem: Microsoft deprecated PowerToys Video Conference Mute (VCM) in v0.88.0 due to virtual camera driver instability and testing overhead. Legacy solutions like
nircmd.exespawn external console processes, add 100-200ms latency, and fail to mute communications endpoints (leaving Zoom, Teams, or Discord calls unmuted). Furthermore, an always-on microphone tray icon adds unnecessary visual clutter, whereas having no indicator leaves users uncertain whether their microphone is active. - Decision:
- Direct WASAPI COM calls via Win32
DllCall: Implemented inAllScripts/SharedHelpers.ahkusingIMMDeviceEnumeratorandIAudioEndpointVolume. Simultaneously targets botheConsole(0) andeCommunications(2) capture endpoints in under 5ms with zero external process spawning. - Dynamic Tray Indicator (Mute-Only Visibility): The tray icon (
mic_muted.ico) appears in the notification area strictly when the microphone is muted (A_IconHidden := false), and is completely hidden when unmuted (A_IconHidden := true). This eliminates taskbar clutter during normal operation while providing an unmistakable indicator when the microphone is muted. - Single-Click Unmuting: Configured
A_TrayMenu.Default := "Unmute Microphone"with single-click execution (A_TrayMenu.ClickCount := 1) to directly unmute the microphone on a single left-click. - Background State Watcher (
WatchMicrophoneMuteState): A lightweight 1500ms timer inBasicTasks.ahksynchronizes the tray icon with hardware mute buttons or third-party app toggles without firing disruptive notifications. - High-Contrast Option 1 Icon Design: Created a custom multi-resolution
.ico(16px to 64px) featuring a solid pure-white (#FFFFFF) microphone body for maximum luminance contrast on dark taskbars (#202020), crossed by a vivid neon-red (#FF2D55) diagonal slash with dark borders. Ensures instant silhouette recognition at arm length on 100% scale displays (16 physical pixels). - StartupScript Tray Exemption:
StartupScript.ahk(TrayIconRemove) explicitly exemptsBasicTasksto prevent mouseover sweeps from removing the active mute indicator.
- Direct WASAPI COM calls via Win32
12. Dynamic Tablet Hibernate Indicator & Pre-Hibernation Display Restoration (SunshineDisplayWatchdog.ahk)
- Context: When streaming to the tablet in Tablet Only mode (
SDC_TOPOLOGY_EXTERNAL = 8, HDMI dummy plug active at 2560x1600 @ 120Hz, laptop internal screen powered off) and the system enters S4 hibernation, waking or turning on the laptop left the internal screen pitch black. - Problem: The Windows lock screen (Winlogon) was displayed on the headless dummy HDMI plug. The user was forced to connect on the tablet via Moonlight just to enter their Windows password.
- Empirical Findings & Root Causes:
- Direct
SetDisplayConfig(..., 0x81)calls from standard user sessions fail with Win32 Error 5 (ERROR_ACCESS_DENIED). - While the secure lock screen (
Winlogon) owns the display, the DirectX graphics kernel (dxgkrnl.sys) actively blocks and times out user-mode display topology changes, generating LiveKernelEvent0x1A8(VIDEO_DXGKRNL_LIVEDUMP) and0x1B8. Consequently, user-space software cannot restore the display once the lock screen is active. - When the user initiates hibernation from the native Start Menu on the tablet stream,
StartMenuExperienceHost.exetriggersSetSuspendStateimmediately.DisplaySwitch.exe /internaltakes ~1.12 seconds, exceeding the OS kernel pre-suspend freeze window.
- Direct
- Decision: Implemented pre-hibernation display restoration driven by a dynamic Tablet Only tray indicator:
- Dynamic Taskbar Tray Indicator: The watchdog displays a custom high-contrast power icon (
tablet_hibernate.ico) in the notification area strictly while in Tablet Only mode (topo == 8). In all other modes (PC Screen Only,Extend,Duplicate), the icon is completely hidden (A_IconHidden := true) to prevent taskbar clutter.StartupScript.ahk(TrayIconRemove) explicitly exemptsSunshineDisplayWatchdogfrom mouseover cleanup sweeps. - Double-Click Confirmation with 5-Second Countdown HUD: Double-clicking the tray icon initiates a live 5-second countdown HUD badge (
[HIBERNATE] Workstation Hibernating in 5s... Press Esc, Del, or click to Cancel). TappingEsc,Delete(essential on tablet keyboards lacking an Esc key), or clicking the badge immediately aborts the timer. - Pre-Hibernation Display Restoration: When the 5-second countdown expires,
ExecuteSafeHibernate()synchronously runsSwitchToLaptopOnlyMode(0, true, true)(RunWait("DisplaySwitch.exe /internal")), allows a 200ms driver settle delay, and then invokesshutdown.exe /h. - Guaranteed Wake Experience: Because the hardware display topology is transitioned to
SDC_TOPOLOGY_INTERNALbeforehiberfil.sysis written, turning on the laptop immediately illuminates the internal 144Hz panel with the Windows lock screen, requiring zero tablet interaction. - Elimination of Flawed Reversion Heuristics:
- Purged both the timer-gap heuristic (
nowTick - g_LastTickCount > 4500) and the legacy 'lid opened' check (hasInternal && monCount <= 1) inWM_DISPLAYCHANGE. In Windows DWM, the dummy plug in Tablet Only mode is automatically assigned device name\\.\DISPLAY1, which previously causedWM_DISPLAYCHANGEto falsely assume the laptop lid had been opened and revert to PC Screen Only every 4 seconds. - Stripped all display switching calls (
DisplaySwitch.exe /internalandSetDisplayConfig 0x81) fromSunshineWatchdog_ForceNormal. Background watchdog events, Tailscale pings, and Sunshine prep-command undo hooks (.session_quit) now manage mouse speed exclusively, preventing background stream glitches from dropping the active tablet display. - Removed automatic display switching from
WM_WTSSESSION_CHANGEonWTS_SESSION_UNLOCK(wParam = 8), guaranteeing that entering a PIN or password on the lock screen via Moonlight preserves Tablet Only mode. - All display switching is strictly explicit: driven by user hotkeys (
Win+Alt+P), master tray menu selections, Tablet Hibernate double-click HUD confirmation, or power resume wake waves.
- Purged both the timer-gap heuristic (
- Dynamic Taskbar Tray Indicator: The watchdog displays a custom high-contrast power icon (
- Context: When streaming to the tablet in Tablet Only mode (
SDC_TOPOLOGY_EXTERNAL = 8), Duplicate mode (SDC_TOPOLOGY_CLONE = 2), or default laptop mirror mode (SDC_TOPOLOGY_INTERNAL = 1), mouse speed must remain at 20 (fast) with precision acceleration disabled during streaming, while restoring cleanly to 10 (normal) when idle or disconnected. - Root Causes:
- Windows DWM and GPU driver adapter handshakes during display switches re-evaluate mouse parameters back to registry defaults, overriding speed 20 set prior to the switch.
- The previous topology guard had a hard cutoff on
topo == 1that forcibly reset speed to 10 and returned early. When a user opened Moonlight on the tablet without pre-switching displays, Sunshine streamed the desktop in default mirror mode, but the watchdog immediately crushed mouse speed back to 10. - When in Tablet Only or Duplicate mode with an idle stream, the topology guard forced speed 20 while the disconnect handler forced speed 10, creating an infinite 1.5-second oscillation loop.
- Invoking
set_normal.ps1from within AutoHotkey created artificial.session_quitmarker files, triggering false session ended logs.
- Architectural Solution:
- Unified Stream State Hierarchy:
SunshineWatchdogTickchecksLastEvent := SunshineWatchdog_LastClientEvent()first. IfLastEvent == "CONNECTED", it boosts mouse speed to 20 acrosstopo == 1(default laptop mirror),topo == 2(duplicate), andtopo == 8(tablet only), while preserving speed 10 ontopo == 4(extend mode with laptop primary). - Oscillation-Free Disconnect Handling: When
LastEvent == "DISCONNECTED"or idle, the watchdog restores normal speed 10 ontopo == 1,topo == 2, andtopo == 4. Ontopo == 8, it clears.fast_sincewithout re-triggering speed 20 or fighting the disconnect handler. - Direct Win32 Execution: AutoHotkey invokes
SystemParametersInfodirectly in 0ms without spawning PowerShell sub-processes, preventing.session_quitmarker contamination. - Post-Switch Settling Enforcement:
SwitchToTabletOnlyModeschedules settling timers (-1200msand-2500ms) viaSunshineDisplay_EnforceTabletMouseSpeedto re-assert speed 20 after DWM re-enumeration finishes. - Dual-Tray Failsafe Toggle:
- Tablet Tray Icon:
UpdateTabletHibernateTrayIconadds a dynamic menu item (Mouse Speed: Fast (20) [Click for Normal]orMouse Speed: Normal (10) [Click for Fast]) that allows 1-click toggling directly from the tablet taskbar in Moonlight. - Master Tray Menu:
PublishSunshineTrayManifest()publishes the live speed label toA_Temp\ahk_traymenu_SunshineDisplayWatchdog.txt.StartupScript.ahk(UpdateSunshineDisplayMenuChecks) dynamically tracks and updates the label inside the master submenu. - Session-Aware Manual Override Lock: Manual toggles engage
g_ManualMouseOverride := trueand snapshotg_ManualOverrideConnectIdfromsunshine.log. The background watchdog strictly respects the user's manual choice without recurring timer reversion loops. Automatic mode automatically resumes when Moonlight disconnects or closes on the tablet, or when a fresh stream reconnection event occurs.
- Tablet Tray Icon:
- Unified Stream State Hierarchy:
14. Dedicated 3-Way Skills Vault Tray Integration & Dynamic Checkmarks (BasicTasks.ahk & StartupScript.ahk)
- Context: Selecting and visualizing the active Skills Vault protection mode (
Auto,Locked,Unlocked) from the Windows system tray. - Problem:
BasicTasks.ahkpreviously published a single cycling menu entry (Skills: Cycle Vault Mode (<current>)tWin+Alt+L). When the vault was locked, the entry displayed(Locked)` persistently, concealing the other available states and requiring blind sequential keyboard toggling. - Decision:
- Three Dedicated Tray Items: Replaced the single cycling entry with 3 discrete menu items published via
PublishBasicTasksManifest:Skills Vault: Auto (Focus-Driven)tWin+Alt+L`Skills Vault: Locked (Org Safe Mode)Skills Vault: Unlocked (Personal Mode)
- Real-Time Win32 Checkmarks:
StartupScript.ahk(UpdateBasicTasksMenuChecks) evaluates%TEMP%\skills_vault_mode.flagand applies native Win32A_TrayMenu.Check()to the active mode while unchecking the other two. Invoked both on initialization and dynamically on mouse up (WM_LBUTTONUP/WM_RBUTTONUP), ensuring the active checkmark is strictly accurate before the menu appears. - Direct 1-Click Mode Selection: Each entry maps to a dedicated label (
TraySkillsVaultAuto,TraySkillsVaultLocked,TraySkillsVaultUnlocked) invokingSetPersonalSkillsMode(targetMode)with a fast 300ms debounce. - Preserved Keyboard Cycling:
Win+Alt+Lremains mapped toTogglePersonalSkillsLock()with its 2000ms debounce settle window for rapid keyboard cycling, automatically synchronizing checkmark placement on next menu view.
- Three Dedicated Tray Items: Replaced the single cycling entry with 3 discrete menu items published via
- Context: In a consolidated fleet architecture,
StartupScript.ahkpresents a single, unified tray icon and context menu for all 11 managed scripts. Individual child scripts must never pollute the Windows notification area with redundant icons. - Problem:
- Boot/Reload Multi-Icon Flash: When child scripts lacked
#NoTrayIcon, Windows Explorer rendered tray icons for all 11 child processes during startup, requiringStartupScript.ahk'sTrayIconRemove()loop to sweep and delete them over several seconds. - Suspend Icon Resurrection: AutoHotkey v2's built-in
Suspend()command internally modifies the tray icon to show the suspended 'S' badge. If an icon was previously deleted from Explorer viaShell_NotifyIcon(NIM_DELETE)without#NoTrayIconset in the script, callingSuspend()caused AutoHotkey's internal engine to assume the icon was active and dispatchShell_NotifyIcon(NIM_ADD), resurrecting all 11 child icons in the task tray on everyWin+Fn+ScrollLockpress.
- Boot/Reload Multi-Icon Flash: When child scripts lacked
- Architectural Solution:
- Mandatory
#NoTrayIconDirective: Every managed child script declares#NoTrayIcondirectly after#Requires AutoHotkey v2.0. This ensuresA_IconHidden == 1inside AutoHotkey's engine from process creation. - Clean Fleet Suspend: Broadcasting
g_FleetControlMsgcode 4 (Suspend(!A_IsSuspended)) leaves child scripts in their hidden state (A_IconHiddenremains true), completely eliminating icon resurrection. - Dynamic Indicator Exception:
BasicTasks.ahk(microphone mute status) andSunshineDisplayWatchdog.ahk(tablet hibernate power button) explicitly setA_IconHidden := falsewhen and only when their visual indicators are needed, and reset toA_IconHidden := truewhen dismissed.StartupScript.ahk(TrayIconRemove) explicitly exempts both scripts from cleanup sweeps.
- Multiline Tray Tooltip DOTALL Regex:
StartupScript.ahk'sTrimAtDelimhelper usesRegExMatch(SubStr(String, 1, Length + 1), "s)(.*)" Delim, &match)with thes)PCRE DOTALL flag, allowing.*to span across newlines and display the maximum number of loaded child scripts within Windows' 124-character tooltip budget.
- Mandatory
16. WSL2 Ext4 Backup SSD Mount Pipeline, PnP Device Revival, and Silent Watchdog Reconciliation (Ext4SsdManager.ahk & PowerShell Engine)
- Context: Automating the mounting, unmounting, and hardware safe removal of an external Linux ext4 NVMe SSD (Pixel 1 Backup SSD) on Windows 11 via WSL2 and Samba.
- Problem:
- WSL2 Swap Partition Crash Loop: Probing partitions with
head -c 512 /dev/sdbtriggered permission denied on the root-owned swap disk, causing falsewsl.exe --shutdowninvocations. - PnP Device Dormancy (
CM_PROB_HELD_FOR_EJECT): Safely ejecting the SSD viaCM_Request_Device_EjectWtransitioned the USB bridge into a dormant state (Code 47). PressingWin+Alt+Mfailed to mount becauseGet-Diskreturned nothing until physical cable reconnection. - Toast Notification Spam: The 5-second background reconciliation watchdog (
ReconcileExt4SsdState) repeatedly fired user-facing toast badges. - Unmount Race Conditions: Lack of lockfile mutual exclusion allowed rapid remount attempts while unmount operations were mid-flight.
- WSL2 Swap Partition Crash Loop: Probing partitions with
- Architectural Solution:
- Deterministic Root lsblk Filtering:
mount_wsl_ssd.ps1runslsblk -b -n -o NAME,SIZE,TYPE,MOUNTPOINTas root to strictly discover non-root partitions exceeding 10 GB, completely eliminating false VM restarts. - Automated PnP Hardware Revival:
Find-EjectedTargetUSBDeviceinssd_common.ps1identifies dormant USB devnodes (VID_0BDA&PID_9210).wsl_mount_elevated.ps1runspnputil /restart-device <InstanceId>with fallback topnputil /remove-device <InstanceId> /forceandpnputil /scan-devices, reviving the bridge and re-attaching\\.\PHYSICALDRIVE*in under 2 seconds. - Silent Background Daemon Discipline: Background watchdog passes explicitly set
showFeedback = false. User-facing HUD badges are strictly reserved for direct keypresses (Win+Alt+M,Win+Alt+U), tray clicks, and physical hardware arrivals. - Mutual Exclusion Lockfile Discipline: Both
mount_wsl_ssd.ps1andunmount_wsl_ssd.ps1enforce$env:TEMP\*.lockfiles with 30-second staleness auto-recovery, preventing conflicting background or manual operations.
- Deterministic Root lsblk Filtering:
| Script | Purpose | Key Hotkeys & Actions |
|---|---|---|
StartupScript.ahk |
Master process orchestrator & unified tray menu | Win+ScrollLock (Suspend all), Win+Ctrl+Alt+ScrollLock (Exit all), Win+Ctrl+Alt+R (Reload all), Win+Ctrl+Alt+W (Window Spy) |
BasicTasks.ahk |
Productivity hotkeys, clipboard converters, microphone mute, DRM mode | Alt+M (Mic mute toggle), Win+Alt+L (Cycle Skills Vault mode), Win+Alt+D (DRM stream toggle), Ctrl+Shift+C (Terminal / Admin pwsh) |
BackgroundAutomations.ahk |
Unattended background daemons & watchers | Sefirah sleep/wake auto-reconnect (port 5150), Skills Vault auto-focus watcher, Tailscale/Google Drive auto-launcher |
Brightness.ahk |
Native Win32 display brightness engine | F1 / Shift+F1 (Step brightness), Ctrl+PgUp / Ctrl+PgDn (Extreme brightness curves) |
ClosePrograms.ahk |
Window management & graceful application termination | Alt+F4 (Close active window), Alt+Shift+F4 (Close specific app), Alt+Ctrl+F4 (Close all apps) |
Ext4SsdManager.ahk |
WSL2 ext4 backup SSD auto-mount & safe ejection | Win+Alt+M (Mount SSD & open Explorer), Win+Alt+U (Safe unmount), auto-mount on USB arrival, #32770 dialog auto-resolver |
HotkeyHelp.ahk |
Self-introspecting two-column hotkey cheatsheet GUI | Win+F1 (Open Hotkey Help GUI), Win+Alt+F1 (Hotkey Help Settings) |
PersonalKeywords.ahk |
Personal hotstrings, snippet expansions, prompt templates | Dynamic string expansions (:X*:...), LLM prompt blueprints |
SunshineDisplayWatchdog.ahk |
Remote streaming display topology & mouse acceleration guard | Win+Alt+P (Toggle PC / Tablet Only), Win+Alt+Shift+P (Extend / Duplicate), auto mouse speed 20 on Moonlight connect |
Watchdog.ahk |
Generic process health monitor | Background polling loop auto-relaunching crashed background utilities |
SharedHelpers.ahk |
Central function library | Named mutexes, debounce engine, bottom-right badges, WASAPI COM mute controls, tray manifests |
To ensure high documentation quality, prevent data leaks, and avoid AI slop in public commits, the repository incorporates autonomous validation tooling.
A zero-dependency Python script that scans tracked and staged files for prohibited punctuation:
- Detects and auto-repairs unicode em-dashes, en-dashes, and comment double-hyphens.
- Enforces natural human punctuation (commas, colons, periods, parentheses).
- Respects syntax exceptions: decrement operators (
i--,counter--), CLI flags (--staged,--check), CSS custom properties (--var), and@vendoredannotations.
Usage Commands:
# Check staged files (exit code 1 if violations found)
python scripts/clean_dashes.py --check
# Auto-repair all staged files before committing
python scripts/clean_dashes.py --staged
# Scan and auto-repair all tracked repository files
python scripts/clean_dashes.py --allConfigured via git config core.hooksPath .githooks. Runs three validation checks before any commit is accepted:
- Check 1: Private Path & Secret Leak Protection: Scans staged content against
LocalPaths.ahk.exampleto ensure personal absolute paths, usernames, and private credentials are never committed. - Check 2: Prohibited File Staging: Prevents staging unencrypted sensitive files, lock files, or temporary manifests.
- Check 3: Dash Linting & Anti-Slop Enforcement: Runs
python scripts/clean_dashes.py --checkacross staged files. If violations exist, commit is blocked with instructions to runpython scripts/clean_dashes.py --staged.
To keep all scripts maintainable and prevent regressions across AI assistants and manual edits, adhere to the following code patterns:
AllScripts/HotkeyHelp.ahk parses .ahk files via regular expressions to build its two-column GUI. To ensure hotkeys render accurately:
- Right arrow for headers: Use
->in section header comments (Key -> Action). - Left arrow for inline descriptions: Use
<-in inline comments (Key::Action ;{ <- Description}). The left arrow visually and syntactically links the description back to the hotkey in the GUI. - Explicit comment on multi-line hotkeys: Hotkeys spanning multiple lines (e.g.
$!F4:: {) or defined within#HotIfcontext blocks (e.g.WheelUp::Send("{Volume_Up}")) must have an inline semicolon comment on the declaration line itself. Without this, Hotkey Help cannot determine the intended description and renders the entry blank.
When automating string expansions or URL navigation via :X*:key.::PasteText("...") in Chromium-based browsers (Chrome, Brave), AutoHotkey's simulated backspaces race against clipboard paste operations.
- Always include a 50ms settle delay (
Sleep(50)) inside clipboard paste helpers between setting clipboard data and executingSendInput("^v").
- No hardcoded fallback leaks: Never write ternary fallbacks like
PATH_VAR ? PATH_VAR : "C:\Program Files\..."in tracked scripts. Even behind a conditional check, the string literal leaks machine-specific paths into the public git log. - Fail open or query registry: If an optional path variable in
LocalPaths.ahkis unset, fail open, skip gracefully, or resolve the executable name directly via Windows registryApp Pathsor the systemPATH.