Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save doc22940/04c06990d2f5b861fea0a80c3fb8c75d to your computer and use it in GitHub Desktop.
Save doc22940/04c06990d2f5b861fea0a80c3fb8c75d to your computer and use it in GitHub Desktop.

Revisions

  1. @dacioromero dacioromero revised this gist Oct 6, 2017. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions AdvancedWindowSnap-Dacio.ahk
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,8 @@
    * Advanced Window Snap
    * Snaps the Active Window to one of nine different window positions.
    *
    * @author Andrew Moore <[email protected]>
    * @version 1.0
    * @author Andrew Moore <[email protected]>, Dacio Romero <[email protected]>
    * @version 1.01
    */

    /**
  2. @dacioromero dacioromero revised this gist Oct 6, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions AdvancedWindowSnap-Dacio.ahk
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,8 @@
    * Advanced Window Snap
    * Snaps the Active Window to one of nine different window positions.
    *
    * @author Andrew Moore <[email protected]>, Dacio Romero <[email protected]>
    * @version 1.01
    * @author Andrew Moore <[email protected]>
    * @version 1.0
    */

    /**
    @@ -25,7 +25,7 @@ SnapActiveWindow(winPlaceVertical, winPlaceHorizontal, winSizeHeight, monitorInd
    WinGet activeWin, ID, A
    monIndex := GetMonitorIndexFromWindow(activeWin)
    } else {
    monIndex := 0
    monIndex := monitorIndex
    }

    SysGet, MonitorWorkArea, MonitorWorkArea, %monIndex%
  3. @dacioromero dacioromero revised this gist Oct 6, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ This fork allow the user to specify a monitor's index when creating new hotkeys.
    2. Copy or Download the **AdvancedWindowSnap-Dacio.ahk** file to your computer and double click it to run it.
    3. (Optional) To have the program run when you start up your computer, place the .ahk file into your computer's [startup] folder.
    * The Windows 7 Startup Folder can be accessed by mousing to **Start** > **All Programs**, then right-clicking on **Startup** and selecting "**Open**".
    * The Windows 8 Startup Folder can be accessed by tapping <kbd>Win</kbd> + <kbd>R</kbd> on your keyboard, then in the Open: field, type `shell:startup` then press <kbd>Enter</kbd>.
    * The Windows 8/10 Startup Folder can be accessed by tapping <kbd>Win</kbd> + <kbd>R</kbd> on your keyboard, then in the Open: field, type `shell:startup` then press <kbd>Enter</kbd>.

    ## Advanced Window Snap Keybindings

  4. @dacioromero dacioromero revised this gist Oct 6, 2017. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    # Advanced Window Snap (Dacio's Mod)
    # Advanced Window Snap (Dacio's Fork)

    Advanced Window Snap is a script for [AutoHotKey] that expands upon Windows built-in window-snapping hotkeys (which are <kbd>Win</kbd> + <kbd>LEFT</kbd> to snap an active window to the left half of a monitor and <kbd>Win</kbd> + <kbd>RIGHT</kbd> to snap a window to the right half of a monitor) by adding 9 additional snap methods. *This version allows for specifying a monitor's index.*
    Advanced Window Snap is a script for [AutoHotKey] that expands upon Windows built-in window-snapping hotkeys (which are <kbd>Win</kbd> + <kbd>LEFT</kbd> to snap an active window to the left half of a monitor and <kbd>Win</kbd> + <kbd>RIGHT</kbd> to snap a window to the right half of a monitor) by adding 9 additional snap methods.

    This fork allow the user to specify a monitor's index when creating new hotkeys. - Dacio Romero

    ## Installation Steps

  5. @dacioromero dacioromero revised this gist Oct 6, 2017. 2 changed files with 7 additions and 5 deletions.
    6 changes: 3 additions & 3 deletions AdvancedWindowSnap.ahk → AdvancedWindowSnap-Dacio.ahk
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,8 @@
    * Advanced Window Snap
    * Snaps the Active Window to one of nine different window positions.
    *
    * @author Andrew Moore <[email protected]>
    * @version 1.0
    * @author Andrew Moore <[email protected]>, Dacio Romero <[email protected]>
    * @version 1.01
    */

    /**
    @@ -18,7 +18,7 @@
    * the active monitor's height. Expecting "half" size,
    * otherwise will resize window to a "third".
    * @param {integer} monitorIndex The index of the monitor the window will be snapped
    * to.
    * to. Leaving value at 0 will find the active monitor.
    */
    SnapActiveWindow(winPlaceVertical, winPlaceHorizontal, winSizeHeight, monitorIndex:=0) {
    if (monitorIndex == 0) {
    6 changes: 4 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    # Advanced Window Snap
    # Advanced Window Snap (Dacio's Mod)

    Advanced Window Snap is a script for [AutoHotKey] that expands upon Windows built-in window-snapping hotkeys (which are <kbd>Win</kbd> + <kbd>LEFT</kbd> to snap an active window to the left half of a monitor and <kbd>Win</kbd> + <kbd>RIGHT</kbd> to snap a window to the right half of a monitor) by adding 9 additional snap methods. *This version allows for specifying a monitor's index.*

    ## Installation Steps

    1. Install [AutoHotKey]
    2. Copy or Download the **AdvancedWindowSnap.ahk** file to your computer and double click it to run it.
    2. Copy or Download the **AdvancedWindowSnap-Dacio.ahk** file to your computer and double click it to run it.
    3. (Optional) To have the program run when you start up your computer, place the .ahk file into your computer's [startup] folder.
    * The Windows 7 Startup Folder can be accessed by mousing to **Start** > **All Programs**, then right-clicking on **Startup** and selecting "**Open**".
    * The Windows 8 Startup Folder can be accessed by tapping <kbd>Win</kbd> + <kbd>R</kbd> on your keyboard, then in the Open: field, type `shell:startup` then press <kbd>Enter</kbd>.
    @@ -45,6 +45,8 @@ Hotkey | Behavior

    - **v1.00**, *08 Jan 2015*
    - Initial Version
    - **v1.01**, *06 Oct 2017*
    - Allow for specifying monitor index

    ## Recommendation For Editing AHK Files
    If you plan on working with AutoHotKey files, consider using [Sublime Text 3]. Read my steps for setting up Sublime Text 3 to edit AutoHotKey files here: [Working with AutoHotKey in Sublime Text].
  6. @dacioromero dacioromero revised this gist Oct 6, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Advanced Window Snap

    Advanced Window Snap is a script for [AutoHotKey] that expands upon Windows built-in window-snapping hotkeys (which are <kbd>Win</kbd> + <kbd>LEFT</kbd> to snap an active window to the left half of a monitor and <kbd>Win</kbd> + <kbd>RIGHT</kbd> to snap a window to the right half of a monitor) by adding 9 additional snap methods.
    Advanced Window Snap is a script for [AutoHotKey] that expands upon Windows built-in window-snapping hotkeys (which are <kbd>Win</kbd> + <kbd>LEFT</kbd> to snap an active window to the left half of a monitor and <kbd>Win</kbd> + <kbd>RIGHT</kbd> to snap a window to the right half of a monitor) by adding 9 additional snap methods. *This version allows for specifying a monitor's index.*

    ## Installation Steps

  7. @dacioromero dacioromero revised this gist Oct 6, 2017. No changes.
  8. @dacioromero dacioromero revised this gist Oct 6, 2017. 1 changed file with 11 additions and 5 deletions.
    16 changes: 11 additions & 5 deletions AdvancedWindowSnap.ahk
    Original file line number Diff line number Diff line change
    @@ -17,12 +17,18 @@
    * @param {string} winSizeHeight The height of the active window in relation to
    * the active monitor's height. Expecting "half" size,
    * otherwise will resize window to a "third".
    * @param {integer} monitorIndex The index of the monitor the window will be snapped
    * to.
    */
    SnapActiveWindow(winPlaceVertical, winPlaceHorizontal, winSizeHeight) {
    WinGet activeWin, ID, A
    activeMon := GetMonitorIndexFromWindow(activeWin)
    SnapActiveWindow(winPlaceVertical, winPlaceHorizontal, winSizeHeight, monitorIndex:=0) {
    if (monitorIndex == 0) {
    WinGet activeWin, ID, A
    monIndex := GetMonitorIndexFromWindow(activeWin)
    } else {
    monIndex := 0
    }

    SysGet, MonitorWorkArea, MonitorWorkArea, %activeMon%
    SysGet, MonitorWorkArea, MonitorWorkArea, %monIndex%

    if (winSizeHeight == "half") {
    height := (MonitorWorkAreaBottom - MonitorWorkAreaTop)/2
    @@ -111,4 +117,4 @@ GetMonitorIndexFromWindow(windowHandle) {
    ; Numberpad Hotkeys (Portrait)
    ^#!Numpad8::SnapActiveWindow("top","full","third")
    ^#!Numpad5::SnapActiveWindow("middle","full","third")
    ^#!Numpad2::SnapActiveWindow("bottom","full","third")
    ^#!Numpad2::SnapActiveWindow("bottom","full","third")
  9. Andrew Moore revised this gist Jan 8, 2015. 1 changed file with 3 additions and 5 deletions.
    8 changes: 3 additions & 5 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ Advanced Window Snap is a script for [AutoHotKey] that expands upon Windows buil
    ## Installation Steps

    1. Install [AutoHotKey]
    2. Copy or Download the **AdvancedWindowSnap.ahk** ([Raw][raw1] | [Gist][gist1]) file to your computer and double click it to run it.
    2. Copy or Download the **AdvancedWindowSnap.ahk** file to your computer and double click it to run it.
    3. (Optional) To have the program run when you start up your computer, place the .ahk file into your computer's [startup] folder.
    * The Windows 7 Startup Folder can be accessed by mousing to **Start** > **All Programs**, then right-clicking on **Startup** and selecting "**Open**".
    * The Windows 8 Startup Folder can be accessed by tapping <kbd>Win</kbd> + <kbd>R</kbd> on your keyboard, then in the Open: field, type `shell:startup` then press <kbd>Enter</kbd>.
    @@ -47,13 +47,11 @@ Hotkey | Behavior
    - Initial Version

    ## Recommendation For Editing AHK Files
    If you plan on working with AutoHotKey files, consider using [Sublime Text 3]. Read my steps for setting up Sublime Text 3 to edit AutoHotKey files here: [Sublime Text & Editing AutoHotKey Files]
    If you plan on working with AutoHotKey files, consider using [Sublime Text 3]. Read my steps for setting up Sublime Text 3 to edit AutoHotKey files here: [Working with AutoHotKey in Sublime Text].

    [AutoHotKey]:http://ahkscript.org/
    [startup]:http://www.autohotkey.com/docs/FAQ.htm#Startup]
    [Sublime Text 3]:http://www.sublimetext.com/3
    [Package Control]:https://packagecontrol.io/installation
    [AutoHotKey Package]:https://packagecontrol.io/packages/AutoHotkey
    [Sublime Text & Editing AutoHotKey Files]:https://github.com/AWMooreCO/AutoHotkey-Scripts/blob/master/README.md
    [raw1]:https://raw.githubusercontent.com/AWMooreCO/AutoHotkey-Scripts/master/AdvancedWindowSnap/AdvancedWindowSnap.ahk
    [gist1]:https://gist.github.com/AWMooreCO/1ef708055a11862ca9dc
    [Working with AutoHotKey in Sublime Text]:https://gist.github.com/AWMooreCO/d0308bab265cc8c5e122
  10. Andrew Moore revised this gist Jan 8, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion AdvancedWindowSnap.ahk
    Original file line number Diff line number Diff line change
    @@ -62,7 +62,7 @@ GetMonitorIndexFromWindow(windowHandle) {
    ; Starts with 1.
    monitorIndex := 1

    VarSetCapacity(monitorInfo, 40)
    VarSetCapacity(monitorInfo, 40)
    NumPut(40, monitorInfo)

    if (monitorHandle := DllCall("MonitorFromWindow", "uint", windowHandle, "uint", 0x2))
  11. Andrew Moore revised this gist Jan 8, 2015. 1 changed file with 59 additions and 0 deletions.
    59 changes: 59 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,59 @@
    # Advanced Window Snap

    Advanced Window Snap is a script for [AutoHotKey] that expands upon Windows built-in window-snapping hotkeys (which are <kbd>Win</kbd> + <kbd>LEFT</kbd> to snap an active window to the left half of a monitor and <kbd>Win</kbd> + <kbd>RIGHT</kbd> to snap a window to the right half of a monitor) by adding 9 additional snap methods.

    ## Installation Steps

    1. Install [AutoHotKey]
    2. Copy or Download the **AdvancedWindowSnap.ahk** ([Raw][raw1] | [Gist][gist1]) file to your computer and double click it to run it.
    3. (Optional) To have the program run when you start up your computer, place the .ahk file into your computer's [startup] folder.
    * The Windows 7 Startup Folder can be accessed by mousing to **Start** > **All Programs**, then right-clicking on **Startup** and selecting "**Open**".
    * The Windows 8 Startup Folder can be accessed by tapping <kbd>Win</kbd> + <kbd>R</kbd> on your keyboard, then in the Open: field, type `shell:startup` then press <kbd>Enter</kbd>.

    ## Advanced Window Snap Keybindings

    ### Directional Arrow Hotkeys:
    Hotkey | Behavior
    ------ | --------
    <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>UP</kbd> | Window will snap to the top **half** of the screen.
    <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>DOWN</kbd> | Window will snap to the bottom **half** of the screen.
    <kbd>Ctrl</kbd> + <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>UP</kbd> | Window will snap to the top **third** of the screen.
    <kbd>Ctrl</kbd> + <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>DOWN</kbd> | Window will snap to the bottom **third** of the screen.

    ### Numberpad Hotkeys (Landscape):
    These will work only if you have NumLock turned **ON**. These are ideal for Landscape Monitors.

    Hotkey | Behavior
    ------ | --------
    <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>Numpad 7</kbd> | Window will snap to the top-left **quarter** of the screen.
    <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>Numpad 8</kbd> | Window will snap to the top **half** of the screen.
    <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>Numpad 9</kbd> | Window will snap to the top-right **quarter** of the screen.
    <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>Numpad 1</kbd> | Window will snap to the bottom-left **quarter** of the screen.
    <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>Numpad 2</kbd> | Window will snap to the bottom **half** of the screen.
    <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>Numpad 3</kbd> | Window will snap to the bottom-right **quarter** of the screen.

    ### Numberpad Hotkeys (Portrait):
    These will work only if you have NumLock turned **ON**. These are ideal for Portrait Monitors.

    Hotkey | Behavior
    ------ | --------
    <kbd>Ctrl</kbd> + <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>Numpad 8</kbd> | Window will snap to the top **third** of the screen.
    <kbd>Ctrl</kbd> + <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>Numpad 5</kbd> | Window will snap to the middle **third** of the screen.
    <kbd>Ctrl</kbd> + <kbd>Win</kbd> + <kbd>Alt</kbd> + <kbd>Numpad 2</kbd> | Window will snap to the bottom **third** of the screen

    ## Changelog

    - **v1.00**, *08 Jan 2015*
    - Initial Version

    ## Recommendation For Editing AHK Files
    If you plan on working with AutoHotKey files, consider using [Sublime Text 3]. Read my steps for setting up Sublime Text 3 to edit AutoHotKey files here: [Sublime Text & Editing AutoHotKey Files]

    [AutoHotKey]:http://ahkscript.org/
    [startup]:http://www.autohotkey.com/docs/FAQ.htm#Startup]
    [Sublime Text 3]:http://www.sublimetext.com/3
    [Package Control]:https://packagecontrol.io/installation
    [AutoHotKey Package]:https://packagecontrol.io/packages/AutoHotkey
    [Sublime Text & Editing AutoHotKey Files]:https://github.com/AWMooreCO/AutoHotkey-Scripts/blob/master/README.md
    [raw1]:https://raw.githubusercontent.com/AWMooreCO/AutoHotkey-Scripts/master/AdvancedWindowSnap/AdvancedWindowSnap.ahk
    [gist1]:https://gist.github.com/AWMooreCO/1ef708055a11862ca9dc
  12. Andrew Moore created this gist Jan 8, 2015.
    114 changes: 114 additions & 0 deletions AdvancedWindowSnap.ahk
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,114 @@
    /**
    * Advanced Window Snap
    * Snaps the Active Window to one of nine different window positions.
    *
    * @author Andrew Moore <[email protected]>
    * @version 1.0
    */

    /**
    * SnapActiveWindow resizes and moves (snaps) the active window to a given position.
    * @param {string} winPlaceVertical The vertical placement of the active window.
    * Expecting "bottom" or "middle", otherwise assumes
    * "top" placement.
    * @param {string} winPlaceHorizontal The horizontal placement of the active window.
    * Expecting "left" or "right", otherwise assumes
    * window should span the "full" width of the monitor.
    * @param {string} winSizeHeight The height of the active window in relation to
    * the active monitor's height. Expecting "half" size,
    * otherwise will resize window to a "third".
    */
    SnapActiveWindow(winPlaceVertical, winPlaceHorizontal, winSizeHeight) {
    WinGet activeWin, ID, A
    activeMon := GetMonitorIndexFromWindow(activeWin)

    SysGet, MonitorWorkArea, MonitorWorkArea, %activeMon%

    if (winSizeHeight == "half") {
    height := (MonitorWorkAreaBottom - MonitorWorkAreaTop)/2
    } else {
    height := (MonitorWorkAreaBottom - MonitorWorkAreaTop)/3
    }

    if (winPlaceHorizontal == "left") {
    posX := MonitorWorkAreaLeft
    width := (MonitorWorkAreaRight - MonitorWorkAreaLeft)/2
    } else if (winPlaceHorizontal == "right") {
    posX := MonitorWorkAreaLeft + (MonitorWorkAreaRight - MonitorWorkAreaLeft)/2
    width := (MonitorWorkAreaRight - MonitorWorkAreaLeft)/2
    } else {
    posX := MonitorWorkAreaLeft
    width := MonitorWorkAreaRight - MonitorWorkAreaLeft
    }

    if (winPlaceVertical == "bottom") {
    posY := MonitorWorkAreaBottom - height
    } else if (winPlaceVertical == "middle") {
    posY := MonitorWorkAreaTop + height
    } else {
    posY := MonitorWorkAreaTop
    }

    WinMove,A,,%posX%,%posY%,%width%,%height%
    }

    /**
    * GetMonitorIndexFromWindow retrieves the HWND (unique ID) of a given window.
    * @param {Uint} windowHandle
    * @author shinywong
    * @link http://www.autohotkey.com/board/topic/69464-how-to-determine-a-window-is-in-which-monitor/?p=440355
    */
    GetMonitorIndexFromWindow(windowHandle) {
    ; Starts with 1.
    monitorIndex := 1

    VarSetCapacity(monitorInfo, 40)♣
    NumPut(40, monitorInfo)

    if (monitorHandle := DllCall("MonitorFromWindow", "uint", windowHandle, "uint", 0x2))
    && DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo) {
    monitorLeft := NumGet(monitorInfo, 4, "Int")
    monitorTop := NumGet(monitorInfo, 8, "Int")
    monitorRight := NumGet(monitorInfo, 12, "Int")
    monitorBottom := NumGet(monitorInfo, 16, "Int")
    workLeft := NumGet(monitorInfo, 20, "Int")
    workTop := NumGet(monitorInfo, 24, "Int")
    workRight := NumGet(monitorInfo, 28, "Int")
    workBottom := NumGet(monitorInfo, 32, "Int")
    isPrimary := NumGet(monitorInfo, 36, "Int") & 1

    SysGet, monitorCount, MonitorCount

    Loop, %monitorCount% {
    SysGet, tempMon, Monitor, %A_Index%

    ; Compare location to determine the monitor index.
    if ((monitorLeft = tempMonLeft) and (monitorTop = tempMonTop)
    and (monitorRight = tempMonRight) and (monitorBottom = tempMonBottom)) {
    monitorIndex := A_Index
    break
    }
    }
    }

    return %monitorIndex%
    }

    ; Directional Arrow Hotkeys
    #!Up::SnapActiveWindow("top","full","half")
    #!Down::SnapActiveWindow("bottom","full","half")
    ^#!Up::SnapActiveWindow("top","full","third")
    ^#!Down::SnapActiveWindow("bottom","full","third")

    ; Numberpad Hotkeys (Landscape)
    #!Numpad7::SnapActiveWindow("top","left","half")
    #!Numpad8::SnapActiveWindow("top","full","half")
    #!Numpad9::SnapActiveWindow("top","right","half")
    #!Numpad1::SnapActiveWindow("bottom","left","half")
    #!Numpad2::SnapActiveWindow("bottom","full","half")
    #!Numpad3::SnapActiveWindow("bottom","right","half")

    ; Numberpad Hotkeys (Portrait)
    ^#!Numpad8::SnapActiveWindow("top","full","third")
    ^#!Numpad5::SnapActiveWindow("middle","full","third")
    ^#!Numpad2::SnapActiveWindow("bottom","full","third")