Skip to content

Instantly share code, notes, and snippets.

@2ajoyce
Last active April 6, 2018 15:52
Show Gist options
  • Save 2ajoyce/821273a7cdfb7534d7b28fb3c617e2dc to your computer and use it in GitHub Desktop.
Save 2ajoyce/821273a7cdfb7534d7b28fb3c617e2dc to your computer and use it in GitHub Desktop.
An AutoHotKey file for resizing windows with behavior similar to OSX
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
I_Icon = C:\Program Files\AutoHotkey\Script Icons\resize.ico
ICON [I_Icon] ;Changes a compiled script's icon (.exe)
if I_Icon <>
IfExist, %I_Icon%
Menu, Tray, Icon, %I_Icon% ;Changes menu tray icon
; Get maximised window size
sysget, SM_CXFULLSCREEN, 16
sysget, SM_CYFULLSCREEN, 17
; Get border and frame stuff
sysget, SM_CXEDGE, 45
sysget, SM_CYEDGE, 46
sysget, SM_CXBORDER, 5
sysget, SM_CYBORDER, 6
sysget, SM_CXSIZEFRAME, 32
sysget, SM_CYSIZEFRAME, 33
; Rename Variables to shorter versions
frameX := (SM_CXSIZEFRAME)
frameY := (SM_CYSIZEFRAME)
width := (SM_CXFULLSCREEN)
height := (SM_CYFULLSCREEN + 40)
return
; Maximize window
^#!Up::
WinGetPos, X, Y, W, H, A
resizeWindow(0-frameX, 0-frameY, (width), (height))
return
; Maximize width
^#!w::
WinGetPos, X, Y, W, H, A
resizeWindow(0-frameX, (Y), (width), (H))
return
; Maximize height
^#!h::
WinGetPos, X, Y, W, H, A
resizeWindow((X), 0, (W), (height-frameY))
return
; Half height Top
^#Up::
WinGetPos, X, Y, W, H, A
resizeWindow((X), 0, (W), (height/2))
return
; Half height Down
^#Down::
WinGetPos, X, Y, W, H, A
resizeWindow((X), (0+height/2), (W), (height/2-frameY))
return
; Left 1/3 of the screen
^#Left::
WinGetPos, X, Y, W, H, A
resizeWindow(0, 0, (width*0.33), (height-frameY))
return
; Left 2/3 of the screen
^#!Left::
WinGetPos, X, Y, W, H, A
resizeWindow(0, 0, (width*0.66), (height-frameY))
return
; Right 1/3 of the screen
^#Right::
WinGetPos, X, Y, W, H, A
resizeWindow((0+width*0.66), 0, (width*0.33+2*frameX), (height-frameY))
return
; Right 2/3 of the screen
^#!Right::
WinGetPos, X, Y, W, H, A
resizeWindow((0+width*0.33), 0, (width*0.66+2*frameX), (height-frameY))
return
; restore original size
^#z::
resizeWindow((X), (Y), (W), (H))
return
resizeWindow(xCord, yCord, width, height)
{
WinGetClass, class, A
WinMove, ahk_class %class%, , xCord, yCord, width, height
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment