Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Moving the active window from one monitor to the other


  • Please log in to reply
7 replies to this topic
JonathanAquino
  • Members
  • 5 posts
  • Last active: Nov 24 2009 11:52 PM
  • Joined: 22 Jul 2006
This script moves the active window from one monitor to the other. It is similar to JumpWin.exe, but that stopped working for me for some reason. UltraMon has similar functionality, but is a bit expensive.

The default hotkey is Ctrl+Alt+Q.

Based on Thalon's code at <!-- m -->http://www.autohotke...topic19440.html<!-- m -->

;Moves the active window from one monitor to the other. Similar to JumpWin.exe, but that stopped working for me for some reason.
;Based on Thalon's code at http://www.autohotkey.com/forum/topic19440.html  [Jon Aquino 2008-09-17]

leftMonitorWidth = 1400
leftMonitorHeight = 1050
rightMonitorWidth = 1920
rightMonitorHeight = 1200

^!q::    ;Default hotkey is Ctrl+Alt+Q
activeWindow := WinActive("A")
if activeWindow = 0
{
    return
}
WinGet, minMax, MinMax, ahk_id %activeWindow%
if minMax = 1
{
    WinRestore, ahk_id %activeWindow%
}
WinGetPos, x, y, width, height, ahk_id %activeWindow%
if x < 0
{
    xScale := rightMonitorWidth / leftMonitorWidth
    yScale := rightMonitorHeight / leftMonitorHeight
    x := leftMonitorWidth + x
    newX := x * xScale
    newY := y * yScale
    newWidth := width * xScale
    newHeight := height * yScale
}
else
{
    xScale := leftMonitorWidth / rightMonitorWidth
    yScale := leftMonitorHeight / rightMonitorHeight
    newX := x * xScale
    newY := y * yScale
    newWidth := width * xScale
    newHeight := height * yScale
    newX := newX - leftMonitorWidth
}
WinMove, ahk_id %activeWindow%, , %newX%, %newY%, %newWidth%, %newHeight%
if minMax = 1
{
    WinMaximize, ahk_id %activeWindow%
}
WinActivate ahk_id %activeWindow%   ;Needed - otherwise another window may overlap it
return


ruespe
  • Members
  • 567 posts
  • Last active: Dec 01 2014 07:59 PM
  • Joined: 17 Jun 2008
Good idea. With SysGet you can retrieve screen resolution and multi-monitor info, so there would be no need for fix resolutions.

Gertlex
  • Members
  • 39 posts
  • Last active: Apr 26 2011 11:38 PM
  • Joined: 29 Oct 2006
Awesome.

Now I just need to get a second monitor :D

JonathanAquino
  • Members
  • 5 posts
  • Last active: Nov 24 2009 11:52 PM
  • Joined: 22 Jul 2006
This works nicely when assigned to pressing both mouse buttons at the same time. Kensington MouseWorks lets me assign this button combination to Ctrl+Alt+Q—perhaps it can be done purely with AutoHotkey as well.

CheeserTheAverage
  • Members
  • 1 posts
  • Last active: Aug 02 2013 12:25 AM
  • Joined: 01 Aug 2013

Thanks for the great script!  One simple change makes this even more sweet.  I prefer to move the window that my mouse is over, even if it's not the active window.  Just add "Click" after "^!q:: " and before "activeWindow := WinActive("A")".



xiaoba
  • Members
  • 2 posts
  • Last active: Sep 29 2013 08:50 PM
  • Joined: 29 Sep 2013

No need to use WinRestore:

winshell_swapScreen(windowTitle := "A") {
    global screenLeftMonitorWidth
    global screenLeftMonitorHeight
    global screenRightMonitorWidth
    global screenRightMonitorHeight

    activeWindow := WinActive(windowTitle)
    borderThreshold := -10
    if activeWindow = 0
    {
        return
    }
    WinGet, minMax, MinMax, ahk_id %activeWindow%
    WinGetPos, x, y, width, height, ahk_id %activeWindow%
    
    if (minMax = 1) {
        ; WinRestore, ahk_id %activeWindow%
        ; a maximized window has x,y = -8,-8 on Windows 8
        newY := y
        if (x > borderThreshold) {
            newX := x - screenLeftMonitorWidth
            newWidth := screenLeftMonitorWidth   - screenRightMonitorWidth  + width
            newHeight := screenLeftMonitorHeight - screenRightMonitorHeight + height
        } else {
            newX := x + screenLeftMonitorWidth
            newWidth := screenRightMonitorWidth   - screenLeftMonitorWidth  + width
            newHeight := screenRightMonitorHeight - screenLeftMonitorHeight + height
        }
    } else {
        WinGetPos, x, y, width, height, ahk_id %activeWindow%
        if (x > borderThreshold) {
            xScale := screenLeftMonitorWidth / screenRightMonitorWidth
            yScale := screenLeftMonitorHeight / screenRightMonitorHeight
            newX := x * xScale
            newY := y * yScale
            newWidth := width * xScale
            newHeight := height * yScale
            newX := newX - screenLeftMonitorWidth
        } else {
            xScale := screenRightMonitorWidth / screenLeftMonitorWidth
            yScale := screenRightMonitorHeight / screenLeftMonitorHeight
            x := screenLeftMonitorWidth + x
            newX := x * xScale
            newY := y * yScale
            newWidth := width * xScale
            newHeight := height * yScale
        }
    }
    WinMove, ahk_id %activeWindow%, , %newX%, %newY%, %newWidth%, %newHeight%
    /*
    if (minMax = 1) {
        WinMaximize, ahk_id %activeWindow%
    }
    */
    WinActivate ahk_id %activeWindow%  ;Needed - otherwise another window may overlap it
    return
}

 



xiaoba
  • Members
  • 2 posts
  • Last active: Sep 29 2013 08:50 PM
  • Joined: 29 Sep 2013

Actually, on Windows 8 (7?), one can just press Win + Shift + Arrow to move a window between screens.



Wade Hatler
  • Members
  • 40 posts
  • Last active: Nov 06 2014 10:46 PM
  • Joined: 28 Sep 2004
the shortcuts were actually added in Windows Vista. there are also a bunch of others built in. For example Win+Right or Left snaps the window to the left or the right half of the monitor. There are a few others, but those are the most useful.