AutoHotkey Community

It is currently May 26th, 2012, 9:08 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Half Windows Script
PostPosted: April 13th, 2009, 9:37 am 
Offline

Joined: April 13th, 2009, 8:24 am
Posts: 5
Hi there,

HalfWindows.ahk is a small script I wrote that allows windows to be positioned using the Ctrl+Arrow key.

For example, Ctrl+Left Arrow moves the window to the left half of the screen. Ctrl+Up arrow moves the window to the top half, etc.

The latest version of the script can be found on the wiki: http://www.autohotkey.com/wiki/index.php?title=Half_Windows


This is the current script.

Code:
; HalfWindows.ahk - Troy Chard - version 1.1 - April 13, 2009
; AutoHotkey Script
; Description: Ctrl+Arrow moves window to that half of the screen.
; eg: Ctrl+LeftArrow moves window to left half screen.  Ctrl+TopArrow to
; the top half of screen.  etc.

#NoEnv  ; for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; for new scripts, superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; It's best to compute work area every time as user may alter
; task bar position or screen-res.

LeftHalfWindow()
{
   SysGet, area, MonitorWorkArea
   w:=((areaRight-areaLeft)/2)
   h:=(areaBottom-areaTop)

   WinRestore, A   
   WinMove, A, , 0, 0,%w%,%h%
}

RightHalfWindow()
{
   SysGet, area, MonitorWorkArea
   w:=((areaRight-areaLeft)/2)
   h:=(areaBottom-areaTop)

   WinRestore, A
   WinMove, A, , w, 0, w, h   ;Middle of screen is same as w.
}

TopHalfWindow()
{
   SysGet, area, MonitorWorkArea
   w:=(areaRight-areaLeft)
   h:=((areaBottom-areaTop)/2)

   WinRestore, A
   WinMove, A, , 0, 0, w, h
}

BottomHalfWindow()
{
   SysGet, area, MonitorWorkArea
   w:=(areaRight-areaLeft)
   h:=((areaBottom-areaTop)/2)

   WinRestore, A
   WinMove, A, , 0, h, w, h   ;Middle of screen is same as h.
}

;Key Bindings
; Ctrl+Arrow Key moves window to that 1/2 of screen.
; eg: Ctrl+UpArrow moves to top 1/2 of screen.

^Left::  LeftHalfWindow()
^Right:: RightHalfWindow()

^Up::   TopHalfWindow()
^Down:: BottomHalfWindow()


Troy


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 13th, 2009, 9:52 am 
Offline

Joined: April 13th, 2009, 8:24 am
Posts: 5
Hi,

Also, I'd really like to add some logic to determine if a window is a top-level application window.

Does anyone know of a simple way of determining this?

Any other comments are welcome too.

Troy


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2009, 7:09 am 
Offline

Joined: August 24th, 2005, 5:17 pm
Posts: 1237
A nice, straightforward script. Thanks.

Someone else may know of a simple way to determine if a window is top-level or not, but I suspect there may be exceptions to any simple solutions and it will just end up bloating the code.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2009, 10:38 am 
Hi Troy_C

Thanks for this script I was going to do something like that to but you go to it even before I had to think about it :)

Thanks muchly.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 14th, 2009, 6:51 pm 
Offline

Joined: April 13th, 2009, 8:24 am
Posts: 5
Thanks guys :)

@evl: re: top level windows. Yep, my attempts to do that were pretty messy too. Still though, sometimes a dialog window that isn't meant to be re-sized can get "half-windowed" too. ah well.... if I find a fix I'll update the wiki for sure.

Troy


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2009, 1:56 am 
Offline

Joined: April 8th, 2009, 11:33 am
Posts: 13
Funny I made something similar on Monday but didn't think anyone would want it.

Here's my take, using the Windows+Numpad keys or Windows+Arrow

Windows+Numpad7 = Quarter screen, Top Left
Windows+Numpad9 = Quarter screen, Top Right
Windows+Numpad 1 = Quarter screen, Bottom Left
Windows+Numpad 3 = Quarter screen, Bottom Right

Windows+Numpad5 = Center
Windows+Numpad0 = Minimize
Windows+Numpad. = Hide

Mine doesn't account for multi-monitors though...

Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
SetBatchLines -1
; -------------------
; START CONFIGURATION
; -------------------
HotKey, #Left, StickLeft
HotKey, #Numpad4, StickLeft
HotKey, #NumpadLeft, StickLeft
HotKey, #Right, StickRight
HotKey, #Numpad6, StickRight
HotKey, #NumpadRight, StickRight
HotKey, #Up, StickUp
HotKey, #Numpad8, StickUp
HotKey, #NumpadUp, StickUp
HotKey, #Down, StickDown
HotKey, #Numpad2, StickDown
HotKey, #NumpadDown, StickDown
HotKey, #Numpad5, CenterWindow
HotKey, #NumpadClear, CenterWindow
HotKey, #Numpad7, StickNW
HotKey, #NumpadHome, StickNW
HotKey, #Numpad1, StickSW
HotKey, #NumpadEnd, StickSW
HotKey, #Numpad9, StickNE
HotKey, #NumpadPgUp, StickNE
HotKey, #Numpad3, StickSE
HotKey, #NumpadPgDn, StickSE
HotKey, #Numpad0, MinWin
HotKey, #NumpadIns, MinWin
HotKey, #NumpadDot, TrayWin
HotKey, #NumpadDel, TrayWin
; --------------------
; END OF CONFIGURATION
; --------------------
OnExit, ExitSub
IsHidden = 0
return


StickLeft:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , 0, 0, A_ScreenWidth / 2, A_ScreenHeight - 30
return


StickRight:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , A_ScreenWidth / 2, 0, A_ScreenWidth / 2, A_ScreenHeight - 30
return


StickUp:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , 0, 0, A_ScreenWidth, (A_ScreenHeight - 30 ) / 2
return


StickDown:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , 0, (A_ScreenHeight - 30 ) / 2, A_ScreenWidth, (A_ScreenHeight - 30 ) / 2
return


CenterWindow:
    WinGetPos, , , WW, WH, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , ( A_ScreenWidth - WW ) / 2, (A_ScreenHeight - 30 - WH ) / 2
return


StickNW:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , 0, 0, A_ScreenWidth / 2, (A_ScreenHeight - 30 ) / 2
return


StickSW:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , 0, (A_ScreenHeight - 30 ) / 2, A_ScreenWidth / 2, (A_ScreenHeight - 30 ) / 2
return


StickNE:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , A_ScreenWidth / 2, 0, A_ScreenWidth / 2, (A_ScreenHeight - 30 ) / 2
return


StickSE:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , A_ScreenWidth / 2, (A_ScreenHeight - 30 ) / 2, A_ScreenWidth / 2, (A_ScreenHeight - 30 ) / 2
return


MinWin:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMinimize, A
return


TrayWin:
    WinGet, UID, ID, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        GroupAdd, TrayWindow, ahk_id %UID%
    if IsHidden = 0
    {
        WinHide, ahk_group TrayWindow
        IsHidden = 1
        ;TrayTip,, hidden 1
    }
    else
    {
        WinShow, ahk_group TrayWindow
        IsHidden = 0
        ;TrayTip,, hidden 0
    }
return


ExitSub:
    WinShow, ahk_group TrayWindow
    ExitApp


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2009, 7:05 pm 
Offline

Joined: April 13th, 2009, 8:24 am
Posts: 5
Heya PaftDunk,

Just tried it out. That's a pretty handy script too. Nice :)

Troy


Report this post
Top
 Profile  
Reply with quote  
PostPosted: July 1st, 2009, 4:41 pm 
Based on paftdunk's script, I added the possibility to fine-tune the window size in steps of 1/6 of screen size.

The script is useful for big screens like 1920x1200 and allows to arrange windows in a lot of useful combinations, e.g. three windows full height side-by-side, or 1 window 2/3 wide of the screen and two windows sharing the remaining 1/3.

I added functions to expand and contract the window to the left, right, up and down.

Windows key + Numpad Division expands to the left,
Windows key + Numpad Multiplication expands to the right,
Windows key + Numpad Subtraction expands to the top,
Windows key + Numpad Addition expands to the bottom,
Windows key + Alt + (same key as above) contracts the respective window from that margin.

Another small change is a bigger value for the bottom offset (changed 30 to 60) - in my layout, the system tray is thicker and 30 did not work well, a small part of the window remained hidden behind it.

Code:
; Easy window location and size utility "One sixth", version 1.0
; Based on script by paftdunk
; Modifications by Mak Sym

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
SetBatchLines -1
; -------------------
; START CONFIGURATION
; -------------------
HotKey, #Left, StickLeft
HotKey, #Numpad4, StickLeft
HotKey, #NumpadLeft, StickLeft
HotKey, #Right, StickRight
HotKey, #Numpad6, StickRight
HotKey, #NumpadRight, StickRight
HotKey, #Up, StickUp
HotKey, #Numpad8, StickUp
HotKey, #NumpadUp, StickUp
HotKey, #Down, StickDown
HotKey, #Numpad2, StickDown
HotKey, #NumpadDown, StickDown
HotKey, #Numpad5, CenterWindow
HotKey, #NumpadClear, CenterWindow
HotKey, #Numpad7, StickNW
HotKey, #NumpadHome, StickNW
HotKey, #Numpad1, StickSW
HotKey, #NumpadEnd, StickSW
HotKey, #Numpad9, StickNE
HotKey, #NumpadPgUp, StickNE
HotKey, #Numpad3, StickSE
HotKey, #NumpadPgDn, StickSE
HotKey, #Numpad0, MinWin
HotKey, #NumpadIns, MinWin
HotKey, #NumpadDot, TrayWin
HotKey, #NumpadDel, TrayWin

HotKey, #NumpadDiv, ExpandLeft
HotKey, #NumpadMult, ExpandRight
HotKey, #!NumpadDiv, ContractLeft
HotKey, #!NumpadMult, ContractRight

HotKey, #NumpadSub, ExpandUp
HotKey, #NumpadAdd, ExpandDown
HotKey, #!NumpadSub, ContractUp
HotKey, #!NumpadAdd, ContractDown

; --------------------
; END OF CONFIGURATION
; --------------------
OnExit, ExitSub
IsHidden = 0
return

ExpandLeft:
    WinGetPos, WX, WY, WW, WH, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , WX - (A_ScreenWidth / 6), , WW + (A_ScreenWidth / 6)
return

ContractLeft:
    WinGetPos, WX, WY, WW, WH, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , WX + (A_ScreenWidth / 6), , WW - (A_ScreenWidth / 6)
return

ExpandRight:
    WinGetPos, WX, WY, WW, WH, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , WX, , WW + (A_ScreenWidth / 6)
return

ContractRight:
    WinGetPos, WX, WY, WW, WH, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , WX, , WW - (A_ScreenWidth / 6)
return

ExpandUp:
    WinGetPos, WX, WY, WW, WH, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , , WY - ((A_ScreenHeight - 60) / 6), , WH + ((A_ScreenHeight - 60) / 6)
return

ContractUp:
    WinGetPos, WX, WY, WW, WH, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , , WY + ((A_ScreenHeight - 60) / 6), , WH - ((A_ScreenHeight - 60) / 6)
return

ExpandDown:
    WinGetPos, WX, WY, WW, WH, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , , WY, , WH + ((A_ScreenHeight - 60) / 6)
return

ContractDown:
    WinGetPos, WX, WY, WW, WH, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , , WY, , WH - ((A_ScreenHeight - 60) / 6)
return


StickLeft:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , 0, 0, A_ScreenWidth / 2, A_ScreenHeight - 60
return


StickRight:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , A_ScreenWidth / 2, 0, A_ScreenWidth / 2, A_ScreenHeight - 60
return


StickUp:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , 0, 0, A_ScreenWidth, (A_ScreenHeight - 60 ) / 2
return


StickDown:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , 0, (A_ScreenHeight - 60 ) / 2, A_ScreenWidth, (A_ScreenHeight - 60 ) / 2
return


CenterWindow:
    WinGetPos, , , WW, WH, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , ( A_ScreenWidth - WW ) / 2, (A_ScreenHeight - 60 - WH ) / 2
return


StickNW:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , 0, 0, A_ScreenWidth / 2, (A_ScreenHeight - 60 ) / 2
return


StickSW:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , 0, (A_ScreenHeight - 60 ) / 2, A_ScreenWidth / 2, (A_ScreenHeight - 60 ) / 2
return


StickNE:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , A_ScreenWidth / 2, 0, A_ScreenWidth / 2, (A_ScreenHeight - 60 ) / 2
return


StickSE:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMove, A, , A_ScreenWidth / 2, (A_ScreenHeight - 60 ) / 2, A_ScreenWidth / 2, (A_ScreenHeight - 60 ) / 2
return


MinWin:
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        WinMinimize, A
return


TrayWin:
    WinGet, UID, ID, A
    WinGetClass, class, A
    if class != Shell_TrayWnd
    if class != Progman
    if class != DV2ControlHost
        GroupAdd, TrayWindow, ahk_id %UID%
    if IsHidden = 0
    {
        WinHide, ahk_group TrayWindow
        IsHidden = 1
        ;TrayTip,, hidden 1
    }
    else
    {
        WinShow, ahk_group TrayWindow
        IsHidden = 0
        ;TrayTip,, hidden 0
    }
return


ExitSub:
    WinShow, ahk_group TrayWindow
    ExitApp

[Moderator's note: Corrected code tags.]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2009, 11:11 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
My approach: WindowPad. There's also an even older script by JOnGliko: HiRes Screen Splitter.


Mak Sym, instead of
Code:
WinGetClass, class, A
if class != Shell_TrayWnd
if class != Progman
if class != DV2ControlHost
you can write
Code:
WinGetClass, class, A
if class not in Shell_TrayWnd,Progman,DV2ControlHost
or even better, you can entirely disable the hotkeys for selected windows. Add this before your START CONFIGURATION section:
Code:
; Add excluded windows to the "Excluded" group:
GroupAdd, Excluded, ahk_class Shell_TrayWnd
GroupAdd, Excluded, ahk_class Progman
GroupAdd, Excluded, ahk_class DV2ControlHost
; Applies to hotkeys created afterwards with the Hotkey command:
Hotkey, IfWinNotActive, ahk_group Excluded
; This would also work for hotkeys between this and the next #IfWin:
;   #IfWinNotActive, ahk_group Excluded
Then you no longer need to check the active window in each hotkey.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: 1337
PostPosted: October 12th, 2009, 10:51 pm 
My man, thank you so very much for writing this script. I just discorvered AutoHotkey one hour ago, and I love it. A combination of AutoHotkey + Desktops v1.0 (http://technet.microsoft.com/en-us/sysi ... 17881.aspx) breahts so much fresh are into my Windows XP.

MUCH LOVE! :-)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2009, 9:13 am 
Hi again,

Some questions:
- Is it possible to get this to work with an external screen?
- If yes, could "move window to next screen" function be implemented?

This script is WAY snappier than the WindowPad script, which is sluggish in my opinion. The fewer lines of code, the better is my software vision :-)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2009, 2:06 pm 
Another very good alternative, GridMove: http://www.donationcoder.com/Forums/bb/index.php?topic=3824

It works very well in a multi-monitor environment and you can use the mouse or the keyboard to move windows.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2009, 2:08 pm 
Here is a direct link to the GridMove project page: http://jgpaiva.dcmembers.com/gridmove.html


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2009, 2:42 pm 
RocknRoller, nice tips.

However, I prefer the non-nonsense approach to the script by Troy_C.
I would LOVE if somebody could make this script support dual monitors(!) and implement a "send window to next screen" function.
It's very few codes needed if you know what you're doing (which I don't :-))

Thanks in advance guys, and continue to have a great day.


:D

foobar


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2009, 3:03 pm 
Offline

Joined: November 10th, 2007, 3:30 am
Posts: 93
Location: Second star to the right.... watching you.
For the ultimate, check out GridMove @ http://jgpaiva.dcmembers.com/gridmove.html

PS, it's made in AHK.

Update: O! Someone beat me to it.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], iBob35555VR and 10 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group