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 

move an window to edge of screen [Func]

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



Joined: 11 Mar 2008
Posts: 291

PostPosted: Sun Apr 13, 2008 5:32 pm    Post subject: move an window to edge of screen [Func] Reply with quote

Code:
; Simply moves an window to edge of screen
;     ______________
;    |LU          RU|
;    |              |
;    |              |
;    |LB          RB|
;     `````(``)``````
;        /``````\


Edge(wTitle, Pos="LU")
{
   IfWinExist, %wTitle%
   {
      WinGetPos,,,w,h
      SysGet, WMax, 16
      SysGet, HMax, 17
      SysGet, HB, 31
   If pos = LU
   WinMove, %wTitle%,,0, 0
   Else If pos = LB
   {
      HH := HMax - h + HB
      WinMove, %wTitle%,,0, %HH%
   }
   Else If pos = RU
   {
      WW := WMax - w
      WinMove, %wTitle%,,%WW%, 0
   }
   Else If pos = RB
   {
      WW := WMax - w
      HH := HMax - h + HB
      WinMove, %wTitle%,,%WW%, %HH%
   }
   }
}



;Example:
F9::Edge("Untitled - Notepad")
F10::Edge("Untitled - Notepad", "RU")
F11::Edge("Untitled - Notepad", "LB")
F12::Edge("Untitled - Notepad", "RB")


not much tested
Back to top
View user's profile Send private message
Oberon



Joined: 18 Feb 2008
Posts: 458

PostPosted: Mon Apr 14, 2008 1:49 pm    Post subject: Reply with quote

That's pretty useful. You've inspired me to write my own version (hope you don't mind):

Code:
SetTitleMatchMode, 2
MoveWindow(4, false, "Notepad") ; example

MoveWindow(Quadrant = 1, Center = false, WinTitle = "", WinText = "", ExcludeTitle = "", ExcludeText = "") {
   IfWinNotExist, %WinTitle%, %WinText%, %ExcludeTitle%, %ExcludeText%
      Return
   WinGetPos, , , w, h
   SysGet, m, MonitorWorkArea
   If Center = 1
      mRight := w + (mRight - mLeft) // 2, mBottom := h + (mBottom - mTop) // 2
   q := Quadrant
   If q not in 1,2,3,4
      q = 1
   If q in 2,3
      x = %mLeft%
   Else If q in 1,4
      x := mRight - w
   If q in 1,2
      y = %mTop%
   Else If q in 3,4
      y := mBottom - h
   WinMove, %x%, %y%
}


You can use it to position within the centre bound as well as screen edges (see diagram):

Back to top
View user's profile Send private message
airjrdn



Joined: 25 Feb 2008
Posts: 35

PostPosted: Mon Apr 14, 2008 2:42 pm    Post subject: Reply with quote

I've been using a hacked up version of WindowPad (found here on AHK), but would like a trimmed down version. It allows you to hold a key and use the keys on the numeric keypad to move the active window to any corner or middle screen edge. The key I like to use for that is the Windows key.

Edit - I built a basic version that works using the Windows key & numeric keypad.
Code:

    #Numpad1::
        MoveWin("LB")
    return

    #Numpad2::
        MoveWin("MB")
    return

    #Numpad3::
        MoveWin("RB")
    return

    #Numpad4::
        MoveWin("LM")
    return

    #Numpad5::
        MoveWin("MM")
    return

    #Numpad6::
        MoveWin("RM")
    return

    #Numpad7::
        MoveWin("LT")
    return

    #Numpad8::
        MoveWin("MT")
    return

    #Numpad9::
        MoveWin("RT")
    return


MoveWin(MoveToPosition)
{
    WinGetActiveTitle, Title
    SysGet, m, MonitorWorkArea
    WinGetPos, , , w, h, A  ; "A" to get the active window's pos.

    if InStr(MoveToPosition, "LB") > 0
    {
        x := 0
        y := mBottom - h
    }

    if InStr(MoveToPosition, "MB") > 0
    {
        x := (mRight / 2) - (w / 2)
        y := mBottom - h
    }

    if InStr(MoveToPosition, "RB") > 0
    {
        x := mRight - w
        y := mBottom - h
    }

    if InStr(MoveToPosition, "LM") > 0
    {
        x := 0
        y := (mBottom / 2) - (h / 2)
    }

    if InStr(MoveToPosition, "MM") > 0
    {
        x := (mRight / 2) - (w / 2)
        y := (mBottom / 2) - (h / 2)
    }

    if InStr(MoveToPosition, "RM") > 0
    {
        x := mRight - w
        y := (mBottom / 2) - (h / 2)
    }

    if InStr(MoveToPosition, "LT") > 0
    {
        x := 0
        y := 0
    }

    if InStr(MoveToPosition, "MT") > 0
    {
        x := (mRight / 2) - (w / 2)
        y := 0
    }

    if InStr(MoveToPosition, "RT") > 0
    {
        x := mRight - w
        y := 0
    }

    WinMove, %Title%,, %x%, %y%
}
Back to top
View user's profile Send private message
holomind



Joined: 11 Mar 2006
Posts: 300
Location: Munich, Germany

PostPosted: Tue Apr 15, 2008 11:23 pm    Post subject: Reply with quote

hi, a similar but more compact version can be found here:
http://www.autohotkey.com/forum/viewtopic.php?p=77405#77405

you might also like a variaton of this with mouse gestures:
http://www.autohotkey.com/forum/viewtopic.php?t=12524

Greetings
Daniel
Back to top
View user's profile Send private message Visit poster's website
airjrdn



Joined: 25 Feb 2008
Posts: 35

PostPosted: Wed Apr 16, 2008 3:33 pm    Post subject: Reply with quote

That one is very close, but it resizes the window for keys 2,4,6,8 whereas mine just centers it on those edges. I think I will adjust it to match my functionality because of it's compactness though. Thanks for sharing!
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Thu Apr 17, 2008 2:42 am    Post subject: Reply with quote

thanks for improvements
and also thanks for the notice holomind
i think it's good as it is that we can gather all related scripts here! Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   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