Skip to content

Instantly share code, notes, and snippets.

@dlimpid
Last active November 20, 2018 12:38
Show Gist options
  • Save dlimpid/6525512 to your computer and use it in GitHub Desktop.
Save dlimpid/6525512 to your computer and use it in GitHub Desktop.
My AutoHotkey Macros - volume, window position and z-position
; variables
; TODO:
; Variables should be at the very top of the script, before any hotkeys.
; Use `gosub` or something else and wrap in the windows size block
narrowWidth := 2 / 5
normalWidth := 1 / 2
wideWidth := 1 - narrowWidth
; Volume
; #Numpad8::Send {Volume_Up}
; #Numpad5::Send {Volume_Mute}
; #Numpad2::Send {Volume_Down}
; Windows size and z-position
#Numpad7::winMoveGrid(0, normalWidth, 0, 1 / 2)
#Numpad4::winMoveGrid(0, normalWidth, 0, 1)
#Numpad1::winMoveGrid(0, normalWidth, 1 / 2, 1)
#^Numpad7::winMoveGrid(0, wideWidth, 0, 1 / 2)
#^Numpad4::winMoveGrid(0, wideWidth, 0, 1)
#^Numpad1::winMoveGrid(0, wideWidth, 1 / 2, 1)
#!Numpad7::winMoveGrid(0, narrowWidth, 0, 1 / 2)
#!Numpad4::winMoveGrid(0, narrowWidth, 0, 1)
#!Numpad1::winMoveGrid(0, narrowWidth, 1 / 2, 1)
#Numpad9::winMoveGrid(1 - normalWidth, 1, 0, 1 / 2)
#Numpad6::winMoveGrid(1 - normalWidth, 1, 0, 1)
#Numpad3::winMoveGrid(1 - normalWidth, 1, 1 / 2, 1)
#^Numpad9::winMoveGrid(1 - wideWidth, 1, 0, 1 / 2)
#^Numpad6::winMoveGrid(1 - wideWidth, 1, 0, 1)
#^Numpad3::winMoveGrid(1 - wideWidth, 1, 1 / 2, 1)
#!Numpad9::winMoveGrid(1 - narrowWidth, 1, 0, 1 / 2)
#!Numpad6::winMoveGrid(1 - narrowWidth, 1, 0, 1)
#!Numpad3::winMoveGrid(1 - narrowWidth, 1, 1 / 2, 1)
#Numpad8::winMoveGrid(0, 1, 0, 1 / 2)
#Numpad5::winMoveGrid(0.15, 0.85, 0.05, 0.95)
#Numpad2::winMoveGrid(0, 1, 1 / 2, 1)
#z::Send !{Space}s{Down}{Right}
#a::WinSet, AlwaysOnTop, Toggle, A ; make activated window be always on top
LWin & LButton:: ; minimize window under the cursor
MouseGetPos, , , id
WinMinimize, ahk_id %id%, , Program Manager
return
LWin & RButton:: ; close window under the cursor
MouseGetPos, , , id
WinClose, ahk_id %id%, , , Program Manager
return
; remap Win+F to Search Everything
#F::Run "C:\Program Files\Everything\Everything.exe"
; turn off monitor
#+L::Run "D:\Programs\Portable\NirCmd\nircmd.exe" cmdwait 1000 monitor off
; hotkeys and hotstrings
~^!'::autoPair("‘", "’") ; smart single quotes
~^!+'::autoPair("“", "”") ; smart double quotes
~^!,::autoPair("〈", "〉")
~^!+,::autoPair("《", "》")
:*?:\...\::⋯
:*?:\--\::– ; En dash
:*?:\---\::— ; Em dash
; Alt + Drag to dragging the window anywhere other than title bar
; Alt & LButton::Gosub, altDrag
; temporary
; #c::
; Loop
; {
; GetKeyState, state, LControl
; If state = D
; break
; Click
; }
; return
; ============================================================================
; auto pairing (like Sublime Text)
autoPair(lmark, rmark)
{
; do nothing on Sublime Text
WinGet, processName, ProcessName, A
if (processName = "sublime_text.exe")
{
Return
}
clipSaved := clipboardAll ; save clipboard content
clipboard = ; empty clipboard
Send ^x
ClipWait, 0.5 ; wait a little for clipboard
Send %lmark%^v%rmark%
if (clipboard = "")
{
Send {Left}
}
clipboard := clipSaved ; restore clipboard content
clipSaved = ; free memory
}
; ============================================================================
; Move window position (and size)
; Top left is (0, 0) and bottom right is (1, 1)
winMoveGrid(left, right, top, bottom)
{
currentMonitor := getCurrentMonitor()
SysGet, currentMonitorWorkArea, MonitorWorkArea, %currentMonitor%
currentMonitorWorkWidth := currentMonitorWorkAreaRight - currentMonitorWorkAreaLeft
currentMonitorWorkHeight := currentMonitorWorkAreaBottom - currentMonitorWorkAreaTop
width := currentMonitorWorkWidth * (right - left)
height := currentMonitorWorkHeight * (bottom - top)
WinMove, A, , currentMonitorWorkAreaLeft + left * currentMonitorWorkWidth, currentMonitorWorkAreaTop + top * currentMonitorWorkHeight, width, height
}
; This function is modified from the original: http://www.autohotkey.com/board/topic/85457-detecting-the-screen-the-current-window-is-on/ by irl404 and Leef_me
getCurrentMonitor()
{
SysGet, numberOfMonitors, MonitorCount
WinGetPos, winX, winY, winWidth, winHeight, A
winMidX := winX + winWidth / 2
winMidY := winY + winHeight / 2
Loop %numberOfMonitors%
{
SysGet, monArea, Monitor, %A_Index%
if (winMidX > monAreaLeft && winMidX < monAreaRight && winMidY < monAreaBottom && winMidY > monAreaTop)
return A_Index
}
SysGet, primaryMonitor, MonitorPrimary
MsgBox, "No Monitor Found"
return 1
}
; ============================================================================
; This script modified from the original: http://www.autohotkey.com/docs/scripts/EasyWindowDrag.htm
; by The How-To Geek
; http://www.howtogeek.com
altDrag:
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY, , , ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
return
EWD_WatchMouse:
GetKeyState, EWD_LButtonState, LButton, P
if EWD_LButtonState = U ; Button has been released, so drag is complete.
{
SetTimer, EWD_WatchMouse, off
return
}
GetKeyState, EWD_EscapeState, Escape, P
if EWD_EscapeState = D ; Escape has been pressed, so drag is cancelled.
{
SetTimer, EWD_WatchMouse, off
WinMove, ahk_id %EWD_MouseWin%, , %EWD_OriginalPosX%, %EWD_OriginalPosY%
return
}
; Otherwise, reposition the window to match the change in mouse coordinates caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, EWD_MouseX, EWD_MouseY
WinGetPos, EWD_WinX, EWD_WinY, , , ahk_id %EWD_MouseWin%
SetWinDelay, -1 ; Makes the below move faster/smoother.
WinMove, ahk_id %EWD_MouseWin%, , EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY
EWD_MouseStartX := EWD_MouseX ; Update for the next timer-call to this subroutine.
EWD_MouseStartY := EWD_MouseY
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment