AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Make windows snap to the edges of the screen

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
gahks



Joined: 10 Jan 2009
Posts: 30

PostPosted: Sun Aug 30, 2009 11:45 am    Post subject: Make windows snap to the edges of the screen Reply with quote

A simple script to make windows snap to the edges of the screen when moving them around.
Snap_prox is the snapping distance (from the active window's edge to the edge of the screen).

Cheers
gahks

Code:
;SETTINGS
snap_prox = 15 ;in px
reaction_speed = 100 ;in ms
;Window snapper code
SysGet, screen, MonitorWorkArea
Loop
{
WinGetActiveStats, title_act, w_act, h_act, x_act, y_act ;active window title and dimensions
If (w_act < screenright-snap_prox)
{
If (x_act > screenleft-snap_prox AND x_act < screenleft OR x_act < screenleft+snap_prox AND x_act > screenleft)
   WinMove, %title_act%,, screenLeft
If (x_act + w_act > screenright-snap_prox AND x_act + w_act < screenright OR x_act + w_act < screenright+snap_prox AND x_act + w_act > screenright)
   WinMove, %title_act%,, (screenright-w_act)
}
If (h_act < screenbottom-snap_prox)
{
If (y_act > screentop-snap_prox AND y_act < screentop OR y_act < screentop+snap_prox AND y_act > screentop)
   WinMove, %title_act%,,, screentop
If (y_act + h_act > screenbottom-snap_prox AND y_act + h_act  < screenbottom OR y_act + h_act < screenbottom+snap_prox AND y_act + h_act > screenbottom)
   WinMove, %title_act%,,, (screenbottom-h_act)
}
Sleep, %reaction_speed%
}


Last edited by gahks on Fri Sep 25, 2009 7:35 pm; edited 1 time in total
Back to top
View user's profile Send private message
entropic



Joined: 21 Dec 2008
Posts: 180

PostPosted: Tue Sep 01, 2009 2:50 am    Post subject: Reply with quote

Very cool, thanks for contributing it.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group