Skip to content

Instantly share code, notes, and snippets.

@etherealxx
Created January 9, 2023 03:24
Show Gist options
  • Save etherealxx/e40b141cecaae7bade038e2a45fa5eb2 to your computer and use it in GitHub Desktop.
Save etherealxx/e40b141cecaae7bade038e2a45fa5eb2 to your computer and use it in GitHub Desktop.
Useful Autohotkey script for my 2560x1080 monitor
;ethx
; Ctrl+Win+X will change the current focused window resolution to 1920x1080 positioned in the middle, and pressing again will revert to the previous state.
; Ctrl+Win+Z will toggle the behavior of taskbar (auto hide)
; Ctrl+Win+C will toggle visibility of taskbar (show/hide)
; Ctrl+Win+V is supposed to toggle hide all window and restore it back. Currently it cannot restore all the window back.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
;#Warn ; Enable warnings to assist with detecting common errors, disabled because changing the taskbar behavior will show a warning.
; variables to store the original size and position of the window
winX := 0
winY := 0
winWidth := 0
winHeight := 0
; flag to track whether the window has been resized
isResized := false
; associative array to store the original size and position of different executables
originalSizes := {}
^#x::
; get the title of the focused window
WinGetTitle, title, A
; check if the window has already been resized
if (isResized) {
; get the original size and position of the window from the associative array
winX := originalSizes[title]["winX"]
winY := originalSizes[title]["winY"]
winWidth := originalSizes[title]["winWidth"]
winHeight := originalSizes[title]["winHeight"]
; revert the window to its original size and position
WinMove, A, , winX, winY, winWidth, winHeight
isResized := false
} else {
; get the current size and position of the window
WinGetPos, winX, winY, winWidth, winHeight, A
; check if the window is currently at size 1920x1080
if (winWidth = 1935 and winHeight = 1087) {
; resize and center the window
WinMove, A, , (2560-1800)/2, 30, 1800, 980
isResized := true
} else {
; store the original size and position of the window in the associative array
originalSizes[title] := {winX: winX, winY: winY, winWidth: winWidth, winHeight: winHeight}
; resize and center the window
WinMove, A, , (2560-1935)/2, (1080-1080)/2, 1935, 1087
isResized := true
}
}
return
^#z:: HideShowTaskbar(hide := !hide)
HideShowTaskbar(action) {
static ABM_SETSTATE := 0xA, ABS_AUTOHIDE := 0x1, ABS_ALWAYSONTOP := 0x2
VarSetCapacity(APPBARDATA, size := 2*A_PtrSize + 2*4 + 16 + A_PtrSize, 0)
NumPut(size, APPBARDATA), NumPut(WinExist("ahk_class Shell_TrayWnd"), APPBARDATA, A_PtrSize)
NumPut(action ? ABS_AUTOHIDE : ABS_ALWAYSONTOP, APPBARDATA, size - A_PtrSize)
DllCall("Shell32\SHAppBarMessage", UInt, ABM_SETSTATE, Ptr, &APPBARDATA)
}
^#c::
if toggle := !toggle
{
WinHide ahk_class Shell_TrayWnd
WinHide Start ahk_class Button
}
else
{
WinShow ahk_class Shell_TrayWnd
WinShow Start ahk_class Button
}
return
^#v::
IfWinActive, Program Manager
{
WinMinimizeAllUndo
}
Else
{
WinMinimizeAll
WinActivate, Program Manager
}
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment