Created
May 14, 2025 04:44
-
-
Save LouisGameDev/eb5d5ba7f807ba3ffe6a51b84a0d0e49 to your computer and use it in GitHub Desktop.
Autohotkey Collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance Force | |
;———————————————————————————————————————— | |
; Press Pause to toggle AlwaysOnTop + red 3px border | |
;———————————————————————————————————————— | |
global borderVisible := false | |
global G_hWnd := "" ; Stores the handle of the window being bordered | |
global G_BorderThickness := 3 | |
global G_TimerInterval := 0 ; Update interval in milliseconds | |
Pause:: | |
global borderVisible, G_hWnd, G_BorderThickness, G_TimerInterval | |
; Get active window handle | |
WinGet, current_hWnd, ID, A | |
if (!current_hWnd) ; No active window | |
return | |
; Toggle AlwaysOnTop for the current active window | |
WinSet, AlwaysOnTop, Toggle, ahk_id %current_hWnd% | |
if (borderVisible) { | |
; Border is currently visible (was on G_hWnd), so hide it | |
SetTimer, UpdateBorderPosition, Off | |
Loop, 4 | |
Gui, % "Border" A_Index ":Destroy" | |
borderVisible := false | |
G_hWnd := "" ; Clear the tracked window handle | |
return | |
} else { | |
; Border is not visible, so show it for the current_hWnd | |
G_hWnd := current_hWnd ; Track this window for updates | |
WinGetPos, X, Y, W, H, ahk_id %G_hWnd% | |
Loop, 4 { | |
guiName := "Border" A_Index | |
Gui, %guiName%:+AlwaysOnTop -Caption +ToolWindow +LastFound +E0x20 | |
Gui, %guiName%:Color, FF0000 ; red | |
borderPos := "" ; Initialize to empty | |
if (A_Index = 1) ; top | |
borderPos := "x" X " y" Y " w" W " h" G_BorderThickness | |
else if (A_Index = 2) ; bottom | |
borderPos := "x" X " y" Y + H - G_BorderThickness " w" W " h" G_BorderThickness | |
else if (A_Index = 3) ; left | |
borderPos := "x" X " y" Y " w" G_BorderThickness " h" H | |
else ; right (A_Index = 4) | |
borderPos := "x" X + W - G_BorderThickness " y" Y " w" G_BorderThickness " h" H | |
Gui, %guiName%:Show, %borderPos% NoActivate | |
} | |
borderVisible := true | |
SetTimer, UpdateBorderPosition, %G_TimerInterval% | |
} | |
Return | |
UpdateBorderPosition: | |
global borderVisible, G_hWnd, G_BorderThickness | |
; If border is not supposed to be visible or no window is tracked, stop. | |
if (!borderVisible || !G_hWnd) { | |
SetTimer, UpdateBorderPosition, Off | |
Return | |
} | |
; If the tracked window no longer exists, clean up. | |
if !WinExist("ahk_id " . G_hWnd) { | |
SetTimer, UpdateBorderPosition, Off | |
Loop, 4 | |
Gui, % "Border" A_Index ":Destroy" | |
borderVisible := false | |
G_hWnd := "" | |
Return | |
} | |
; Retrieve current window position and size | |
WinGetPos, X, Y, W, H, ahk_id %G_hWnd% | |
; It's possible the window was minimized or is tiny; handle gracefully | |
if (W <= 0 || H <= 0) { | |
Return ; Don't attempt to draw if window is invalid size | |
} | |
; Update positions of the four border strips | |
Gui, Border1:Show, % "NoActivate x" X " y" Y " w" W " h" G_BorderThickness | |
Gui, Border2:Show, % "NoActivate x" X " y" Y + H - G_BorderThickness " w" W " h" G_BorderThickness | |
Gui, Border3:Show, % "NoActivate x" X " y" Y " w" G_BorderThickness " h" H | |
Gui, Border4:Show, % "NoActivate x" X + W - G_BorderThickness " y" Y " w" G_BorderThickness " h" H | |
Return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoEnv | |
SendMode Input | |
!-::Send — |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment