Jump to content

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

Windows-7 Like Window Positioning for XP and Vista


  • Please log in to reply
80 replies to this topic
wtg
  • Members
  • 251 posts
  • Last active: Dec 19 2012 03:54 PM
  • Joined: 04 Oct 2006
I too would love to see KooKsTeR's script updated to work with multiple monitors. Thankfully you can "Suspend Hotkeys" if you inadvertently move a window to another monitor and need to move it back.

It seems like the script could check to see if the window's position has fully moved off it's original monitor, and if so cancel the half-size snap. Unfortunately I'm having some trouble deciphering exactly where this logic would be added. I really wish there were some comments in there.

ooter
  • Guests
  • Last active:
  • Joined: --

Here is the latest, with every function that I know of in windows 7 Aero Snap:


Love your script. Have a couple suggestions/questions for improvement.

1.) I'm wondering how I can disable the option to arrange windows by dragging. I would prefer to only use hotkeys (this is why I don't use the built-in Aero Snap in Windows 7).

2.) When a window is dragged out of alignment, it is returned to its original size and positioned at the mouse cursor. How can I do this with hot keys?

3.) Support for moving the Windows to a secondary monitor would be great.

I think the best setup for 2 & 3 would be:
Windows Key + Left Arrow arranges the active window on the left side of the primary monitor. If the window is already arranged on the left side of the primary monitor, it is instead arranged on the left side of the secondary monitor. If it is already arranged on the right side of the primary monitor, it is moved to its original (pre-Aero Snap) position.

That sort of setup but for all permutations would be perfect. If someone could tell me how I can achieve that, or at least something close to that, I would really appreciate it.

Thank you,
Derek

blondedude092
  • Members
  • 77 posts
  • Last active: Oct 15 2015 04:51 PM
  • Joined: 07 Jan 2009
This feature is actualy using a docking property, for the desktop.
Now to make it in AHK that would be a pain in the ass, but easy for other coding languages. NOT scripting like ahk.

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
Doing it in ahk isn't that tough, it just requires to get the monitor dimensions, use some math and keep a list of window states.
You can probably even skip the list and detect the state by the window's position. It might have problems with non-sizable windows like cmd though.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
O wow I havent checked in here for a while I didnt know anyone was using my script. Since you guys are. I will check it out again. And sorry my codes hard to follow. This was my first some what major project.

On the note for support for multiple monitors. I am not sure how I can do that, especially since I dont have that set up. So I would need someone to help out with that.

-Kookster

PS: yes its math to calculate the widths and everything. But it was a pain because of the inconsistant width and height that the system actually reports. Long story short its alot harder than it should of been.

Ethere
  • Members
  • 1 posts
  • Last active: Nov 16 2010 08:29 PM
  • Joined: 16 Nov 2010

Here is the latest, with every function that I know of in windows 7 Aero Snap:


Win+Shift+Left and Win+Shift+Right doesn't work to move the window to the next / previous monitor. Using your script works on one monitor, but trying to move a window manually to the second monitor fails since the window "snaps" to either the left or the right of the first monitor.

Keep up the good work guys!

Duplicated. I have two monitors at work, and this would be perfect if it would let me drag the windows across both monitors.

thinkstorm
  • Members
  • 40 posts
  • Last active: Sep 10 2014 06:06 PM
  • Joined: 17 Aug 2004
is this an autogenerated image from splashscreen, or is this something that resides in your autohotkey root directory?

TC
Cheers,

Thorsten

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
Are you asking about the resize preview? If so all it is a gui that i made a specific color and partly transparent. I originally had a image but I decided to leave it out.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
So since I dont have a dual monitor setup I need someone to tell me exactly how aero snap behaves in the middle of where the two monitors 'connect'.

scriptmonkey
  • Members
  • 176 posts
  • Last active: Jan 08 2015 07:42 PM
  • Joined: 19 May 2006
Which script is the latest/greatest?
Zak M.

  • Guests
  • Last active:
  • Joined: --

Which script is the latest/greatest?

#Persistent
detecthiddenwindows ,on

;---------------------------detects closing windows / clears old data

SetBatchLines, -1
Process, Priority,, High
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
Return

ShellMessage( wParam,lParam )
   {
   Global ID
   If ( wParam = 2 )
      {
      SetFormat, Integer, Hex
      ID := lParam + 0
      SetFormat, Integer, D
      SetTimer, MyRoutine, -1
      }
   }

MyRoutine:
if %ID%check=1
   {
   %ID%check=
   %ID%width=
   %ID%height=
   %ID%X=
   }
Return



;--------------------------------------------handles Preview

Win__SplashSet()
{
splashimage,shade2243324.jpg,hide b2
WinSet, Transparent, 85, %A_ScriptName%
x+=3
y+=3
w-=6
h-=6
}

;--------------------------handles checking/storing window information

Win__GetIDInformation(ByRef ID, ByRef Width, ByRef Height)
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
   {
   goto,skip
   }
skip:
sleep 5
}

;-----------------------------------------handles desktop variables

Win__GetDesktopPos(ByRef X, ByRef Y, ByRef W, ByRef H)
{
X := 0
Y := 0
SysGet, MonitorWorkArea, MonitorWorkArea
W:=A_ScreenWidth-2
H=%MonitorWorkAreaBottom%
}

;----------------------------------------handles left half maximize

Win__HalfLeft()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
   {
   goto,skipsave1
   }
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
%ID%x=%x%
ID=
skipsave1:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W/2, H
return
}


;----------------------------------------handles right half maximize

Win__HalfRight()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
   {
   goto,skipsave2
   }
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
%ID%x=%x%
ID=
skipsave2:
Win__GetDesktopPos(X, Y, W, H)
winMove, A,, X + W/2, Y, W/2, H
return
}

;----------------------------------------handles full maximize

Win__FullSize()
{
WinGetActiveStats,Title,Width,Height,X,Y
winget,ID,ID,%Title%
check:=%id%check
if check=1
   {
   goto,skipsave3
   }
%ID%check=1
%ID%Width=%width%
%ID%Height=%height%
%ID%x=%x%
ID=
skipsave3:
Win__GetDesktopPos(X, Y, W, H)
WinMove, A,, X, Y, W, H
return
}

;-----------------------detects when window is being dragged

*~LButton::
CoordMode, Mouse, Screen
MouseGetPos, x, y, hwnd
SendMessage, 0x84, 0, (x&0xFFFF) | (y&0xFFFF) << 16,, ahk_id %hwnd%
RegExMatch("ERROR TRANSPARENT NOWHERE CLIENT CAPTION SYSMENU SIZE MENU HSCROLL VSCROLL MINBUTTON MAXBUTTON LEFT RIGHT TOP TOPLEFT TOPRIGHT BOTTOM BOTTOMLEFT BOTTOMRIGHT BORDER OBJECT CLOSE HELP", "(?:\w+\s+){" . ErrorLevel+2&0xFFFFFFFF . "}(?<AREA>\w+\b)", HT)
if htarea!=TOP
   {
   }
else
   {
   WinGetActiveStats,Title,Width,Height,X,Y
   winget,ID,ID,%Title%
   check:=%id%check
   if check=1
      {
      goto,skiptop
      }
   %ID%check=1
   %ID%Width=%width%
   %ID%Height=%height%
   %ID%x=%x%
   skiptop:
   loop
      {
      sleep 5
      coordmode,mouse,screen
      MouseGetPos,Mouse_X,Mouse_Y
      if (mouse_y=0)
         {
         Win__GetDesktopPos(X, Y, W, H)
         Win__SplashSet()
         wingetactivestats,Title,W,H2,x,Y
         height:=h-h2-y
         winmove,%A_ScriptName%,,X,Y+H2,W,height
         SplashImage, Show, b2,,, SplashImage
         loop
            {
            sleep 5
            coordmode,mouse,screen
            MouseGetPos,Mouse_X,Mouse_Y
            if (mouse_y>0)
               {
               splashimage,off
               goto,skiptop
               }
            If (GetKeyState("LButton","P")=0)
               {
               splashimage,off
               Win__GetDesktopPos(X, Y, W, H)
               winMove,A,,,0,, H
               return
               }
            }
         }
      If (GetKeyState("LButton","P")=0)
         {
         %ID%check=
         %ID%Width=
         %ID%Height=
         %ID%x=
         return
         }
      }
   }
if htarea!=BOTTOM
   {
   }
else
   {
   WinGetActiveStats,Title,Width,Height,X,Y
   winget,ID,ID,%Title%
   check:=%id%check
   if check=1
      {
      goto,skipbottom
      }
   %ID%check=1
   %ID%Width=%width%
   %ID%Height=%height%
   %ID%x=%x%
   skipbottom:
   loop
      {
      sleep 5
      coordmode,mouse,screen
      MouseGetPos,Mouse_X,Mouse_Y
      Win__GetDesktopPos(X, Y, W, H)
      check:=H-mouse_y-1
      if (check<3)
         {
         Win__GetDesktopPos(X, Y, W, H)
         Win__SplashSet()
         wingetactivestats,Title,W,H,x,Y
         winmove,%A_ScriptName%,,X,0,W,Y
         SplashImage, Show, b2,,, SplashImage
         loop
            {
            sleep 5
            coordmode,mouse,screen
            MouseGetPos,Mouse_X,Mouse_Y
            Win__GetDesktopPos(X, Y, W, H)
            check:=H-mouse_y-1
            if (check>3)
               {
               splashimage,off
               goto,skipbottom
               }
            If (GetKeyState("LButton","P")=0)
               {
               splashimage,off
               Win__GetDesktopPos(X, Y, W, H)
               winMove,A,,,0,, H
               return
               }
            }
         }
      If (GetKeyState("LButton","P")=0)
         {
         %ID%check=
         %ID%Width=
         %ID%Height=
         %ID%x=
         return
         }
      }
   }
if htarea!=CAPTION
   {
   Return
   }
 MouseGetPos,_x,_y
 While GetKeyState("LButton","P") && x=_x && y=_y
   {
   start:
   sleep 5
   wingetactivestats,ActiveTitle,Width,Height,x,Y
   winget,test,MinMax,%activetitle%
   if test=1
      {
      return
      }
   coordmode,mouse,screen
   MouseGetPos,Mouse_X,Mouse_Y
   if Mouse_X=0
      {
      Win__GetDesktopPos(X, Y, W, H)
      Win__SplashSet()
      winmove,%A_ScriptName%,,x,y,w/2,h
      SplashImage, Show, b2,,, SplashImage
      loop
         {
         sleep 5
         MouseGetPos,Mouse_X,Mouse_Y
         If (GetKeyState("LButton","P")=0)
            {
            Win__GetIDInformation(ID,Width,Height)
            %ID%check=1
            %ID%Width=%width%
            %ID%Height=%height%
            ID=
            splashimage,off
            Win__GetDesktopPos(X, Y, W, H)
            WinMove, A,, X, Y, W/2, H
            return
            }
         if Mouse_X>0
            {
            splashimage,off
            goto,start
            }
         }
      }
   Win__GetDesktopPos(X,Y,Width,Height)   
   Width-=5
   if (width < mouse_x)
      {
      Win__GetDesktopPos(X, Y, W, H)
      Win__SplashSet()
      winmove,%A_ScriptName%,, X + W/2, Y, W/2, H
      SplashImage, Show, b2,,, SplashImage
      loop
         {
         sleep 5
         MouseGetPos,Mouse_X,Mouse_Y
         If (GetKeyState("LButton","P")=0)
            {
            Win__GetIDInformation(ID,Width,Height)
            %ID%check=1
            %ID%Width=%width%
            %ID%Height=%height%
            ID=
            splashimage,off
            Win__GetDesktopPos(X, Y, W, H)
            winMove, A,, X + W/2, Y, W/2, H
            return
            }
         Win__GetDesktopPos(X,Y,Width,Height)   
         Width-=5
         if (width > mouse_x)
            {
            splashimage,off
            goto,start
            }
         }
      }
   if mouse_y=0
      {
      Win__GetDesktopPos(X, Y, W, H)
      Win__SplashSet()
      winmove,%A_ScriptName%,,X, Y, W, H
      SplashImage, Show, b2,,, SplashImage
      loop
         {
         sleep 5
         MouseGetPos,Mouse_X,Mouse_Y
         If (GetKeyState("LButton","P")=0)
            {
            Win__GetIDInformation(ID,Width,Height)
            %ID%check=1
            %ID%Width=%width%
            %ID%Height=%height%
            ID=
            splashimage,off
            Win__GetDesktopPos(X, Y, W, H)
            winMove, A,, X, Y, W, H
            return
            }
         if mouse_y>3
            {
            splashimage,off
            goto,start
            }
         }
      }
   WinGetActiveStats,Title,Width,Height,X,Y
   winget,ID,ID,%Title%
   check:=%id%check
   if check=1
      {
      WinGetActiveStats,Current_Title,Current_Width,Current_Height,Current_X,Y
      Win__GetDesktopPos(X,Y,Width,Height)
      MouseGetPos,Mouse_Screen
      winget,ID,ID,%current_Title%
      Original_width:=%ID%Width
      Original_height:=%ID%height
      %ID%check=
      %ID%Width=
      %ID%height=
      coordmode,mouse,relative
      MouseGetPos,Mouse_Window
      check:=current_width/2
      if (mouse_window<check)
         {
         ;(left side)
         check:=original_width/2
         if (mouse_window<check)
            {
            if (mouse_window>original_width-75)
               {
               ;(Center the window left)
               x:=mouse_screen-(original_width/2)
               }
            else
               {
               ;(align left side)
               x:=current_x
               }
            goto,end
            }
         }
      check:=current_x+Current_width-Original_width+(original_width/2)
      if (check<mouse_screen)
         {
         ;(align right side)
         x:=current_x+Current_width-Original_width
         goto,end
         }
      if (Mouse_Window<Current_width-75)
         {
         ;(center the window right)
         x:=mouse_screen-(original_width/2)
         goto,end
         }
      end:
      winmove,%Current_Title%,,%x%,,%original_width%,%original_height%
      ID=
      x=
      goto,start
      }
   If (GetKeyState("LButton","P")=0)
      {
      return
      }
   goto,start
   }
Return

;--------------------------------------Shortcut keys

#right::Win__HalfRight()

#left::Win__HalfLeft()

#up::Win__FullSize()

#Down::WinMinimize, A

Also for those of you who are interested, I am about to get a dual monitor setup, so hopefully I will be able to start testing that. Not sure how I am suppose to test it with my vm yet, but im sure i cna find a way.

scriptmonkey
  • Members
  • 176 posts
  • Last active: Jan 08 2015 07:42 PM
  • Joined: 19 May 2006

Also for those of you who are interested, I am about to get a dual monitor setup, so hopefully I will be able to start testing that. Not sure how I am suppose to test it with my vm yet, but im sure i cna find a way.


Thanks for the reply. So this doesnt work with dual monitors?
Zak M.

KooKsTeR
  • Members
  • 157 posts
  • Last active: Aug 21 2015 09:55 PM
  • Joined: 19 Feb 2010
no not yet. When I wrote it, I only had a single monitor, so I didnt know how to code it to work for two. Im also unsure how windows 7 handles it for two monitors

Oldtimer88
  • Members
  • 5 posts
  • Last active: Feb 16 2015 08:37 PM
  • Joined: 23 Mar 2011
hi All, I have Windows-7. I need an AutoHotKey script to work on the selected window to enter "Alt", then "Spacebar", then "m", then press "down arrow" 4 times, then "Enter". I tried to borrrow from the many examples in this long threat but at the end got LOST and extremely frustrated.
I must assume it should be simple, but not for me today.
** I hope I am posting this request at the right place. Thanks for any help.

Gertlex
  • Members
  • 39 posts
  • Last active: Apr 26 2011 11:38 PM
  • Joined: 29 Oct 2006
Props to you, KooKster; Thanks!