Skip to content

Instantly share code, notes, and snippets.

@brianpeiris
Last active September 30, 2021 13:07
Show Gist options
  • Save brianpeiris/a770c89a74464418d3ba to your computer and use it in GitHub Desktop.
Save brianpeiris/a770c89a74464418d3ba to your computer and use it in GitHub Desktop.
An AutoHotKey script for positioning and resizing windows
WindowsHelpers-Run-As-Admin.lnk
; ---
; WindowsHelpers.ahk
; ---
;
; Window management helpers. Plus a few extras.
;
; Note: You'll have to run this AHK script as an Administrator in order to
; move elevated windows and override the default workstation lock hotkey.
; I usually create a shortcut to the script with the "Run as administrator"
; property enabled.
move(x, y, w, h){
windowId:=WinActive("A")
SysGet, WorkArea, MonitorWorkArea
WinMove
, ahk_id %windowId%
, , A_ScreenWidth * x, WorkAreaBottom * y
, A_ScreenWidth * w, WorkAreaBottom * h
}
; Need to use subroutines for RegWrite because apparently functions don't
; get called quickly enough.
DisableLock:
RegWrite
, REG_DWORD, HKEY_CURRENT_USER
, Software\Microsoft\Windows\CurrentVersion\Policies\System
, DisableLockWorkstation, 1
Return
EnableLock:
RegWrite
, REG_DWORD, HKEY_CURRENT_USER
, Software\Microsoft\Windows\CurrentVersion\Policies\System
, DisableLockWorkstation, 0
Return
; ---
; Key layout:
; ---
; u i o
; j k l
; m , .
; ---
; Halves - Win + <key>
; ---
#u::
move(0, 0, 1/2, 1/2)
return
#i::
move(1/4, 0, 1/2, 1/2)
return
#o::
move(1/2, 0, 1/2, 1/2)
return
#j::
move(0, 0, 1/2, 1)
return
#k::
move(1/4, 0, 1/2, 1)
return
#l::
GoSub, DisableLock
move(1/2, 0, 1/2, 1)
return
#m::
move(0, 1/2, 1/2, 1/2)
return
#,::
move(1/4, 1/2, 1/2, 1/2)
return
#.::
move(1/2, 1/2, 1/2, 1/2)
return
; ---
; Thirds - Win + Shift + <key>
; ---
#+u::
move(0, 0, 1/3, 1/2)
return
#+i::
move(1/3, 0, 1/3, 1/2)
return
#+o::
move(2/3, 0, 1/3, 1/2)
return
#+j::
move(0, 0, 1/3, 1)
return
#+k::
move(1/3, 0, 1/3, 1)
return
#+l::
move(2/3, 0, 1/3, 1)
return
#+m::
move(0, 1/2, 1/3, 1/2)
return
#+,::
move(1/3, 1/2, 1/3, 1/2)
return
#+.::
move(2/3, 1/2, 1/3, 1/2)
return
; ---
; Quarters - Win + Ctrl + Shift + <key>
; ---
#^+u::
move(0, 0, 1/4, 1/2)
return
#^+o::
move(3/4, 0, 1/4, 1/2)
return
#^+j::
move(0, 0, 1/4, 1)
return
#^+l::
move(3/4, 0, 1/4, 1)
return
#^+m::
move(0, 1/2, 1/4, 1/2)
return
#^+.::
move(3/4, 1/2, 1/4, 1/2)
return
; ---
; Misc
; ---
#s::
winset, alwaysontop, , A
return
#;::
GoSub, EnableLock
Sleep, 200
DllCall("LockWorkStation")
Sleep, 200
GoSub, DisableLock
return
#PgUp::
Send {Volume_Up}
return
#PgDn::
Send {Volume_Down}
return
#End::
Send {Volume_Mute}
return
@brianpeiris
Copy link
Author

Sure, there's an email address on my profile page, contact me there: https://github.com/brianpeiris

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