 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Troy_C
Joined: 13 Apr 2009 Posts: 5
|
Posted: Mon Apr 13, 2009 8:37 am Post subject: Half Windows Script |
|
|
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 |
|
| Back to top |
|
 |
Troy_C
Joined: 13 Apr 2009 Posts: 5
|
Posted: Mon Apr 13, 2009 8:52 am Post subject: Detect top level application windows improvement |
|
|
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 |
|
| Back to top |
|
 |
evl
Joined: 24 Aug 2005 Posts: 1237
|
Posted: Tue Apr 14, 2009 6:09 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Nice Script Guest
|
Posted: Tue Apr 14, 2009 9:38 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Troy_C
Joined: 13 Apr 2009 Posts: 5
|
Posted: Tue Apr 14, 2009 5:51 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
paftdunk
Joined: 08 Apr 2009 Posts: 13
|
Posted: Wed Apr 15, 2009 12:56 am Post subject: |
|
|
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
|
|
|
| Back to top |
|
 |
Troy_C
Joined: 13 Apr 2009 Posts: 5
|
Posted: Wed Apr 15, 2009 6:05 pm Post subject: |
|
|
Heya PaftDunk,
Just tried it out. That's a pretty handy script too. Nice
Troy |
|
| Back to top |
|
 |
Mak Sym Guest
|
Posted: Wed Jul 01, 2009 3:41 pm Post subject: changing window size in 1/6 steps |
|
|
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.] |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7295 Location: Australia
|
Posted: Thu Jul 02, 2009 10:11 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
foobar Guest
|
Posted: Mon Oct 12, 2009 9:51 pm Post subject: 1337 |
|
|
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/sysinternals/cc817881.aspx) breahts so much fresh are into my Windows XP.
MUCH LOVE!  |
|
| Back to top |
|
 |
foobar Guest
|
Posted: Tue Oct 13, 2009 8:13 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
RocknRoller Guest
|
|
| Back to top |
|
 |
RocknRoller Guest
|
|
| Back to top |
|
 |
foobar Guest
|
Posted: Tue Oct 13, 2009 1:42 pm Post subject: |
|
|
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.
foobar |
|
| Back to top |
|
 |
paxophobe
Joined: 10 Nov 2007 Posts: 93 Location: Second star to the right.... watching you.
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|