Skip to content

Instantly share code, notes, and snippets.

@jcheng31
Last active February 20, 2024 23:45
Show Gist options
  • Save jcheng31/7169828 to your computer and use it in GitHub Desktop.
Save jcheng31/7169828 to your computer and use it in GitHub Desktop.
An AutoHotkey script for widescreen, high-resolution monitors. Resizes the active window to be 75% of the screen's width (and 100% of its height, taskbar excluded) and centres it. Triggered by pressing Win+Shift+Up. Great for websites that don't nicely centre their content. Win+Shift+C now centres the active window without resizing it.
; When Win+Shift+Up is pressed, resize the active window to be 75% of the screen width
; and centre it. Useful for widescreen resolutions >= 1080p, but uses the resolution
; of the primary monitor.
#+Up::
SysGet, BoundingCoordinates, MonitorWorkArea
ResolutionWidth := BoundingCoordinatesRight - BoundingCoordinatesLeft
ResolutionHeight := BoundingCoordinatesBottom - BoundingCoordinatesTop
AdjustedWidth := 0.75 * ResolutionWidth
LeftMargin := 0.125 * ResolutionWidth
WinMove A, , LeftMargin, 0, AdjustedWidth, ResolutionHeight
return
; When Win+Shift+C is pressed, move the active window to the centre of the screen.
#+c::
SysGet, BoundingCoordinates, MonitorWorkArea
ResolutionWidth := BoundingCoordinatesRight - BoundingCoordinatesLeft
ResolutionHeight := BoundingCoordinatesBottom - BoundingCoordinatesTop
WinGetPos, , , ActiveWidth, ActiveHeight, A
HorizontalMargin := (ResolutionWidth - ActiveWidth) / 2
VerticalMargin := (ResolutionHeight - ActiveHeight) / 2
WinMove A, , HorizontalMargin, VerticalMargin
@Splode
Copy link

Splode commented Dec 4, 2015

This is a brilliant little script! It's the exactly the starting point that I was looking for.

Thank you!

@MealdyTech
Copy link

Awesome work, thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment