Last active
September 21, 2024 11:26
-
-
Save haxpor/2932d5e898e40407f142e95900c8cb2e to your computer and use it in GitHub Desktop.
Current active window snapping window to top or bottom half of the screen with Windows+Shift+Up/Down working with API v.1.1 of AutoKey (but works with Autokey latest version from its download). From upstream https://superuser.com/a/1856438/466443
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ---------- | |
; Move window up (Windows + Shift + UP) | |
+#Up:: | |
target_monitor := 2 | |
SysGet, MonitorCount, MonitorCount | |
; get current active window | |
WinGetPos, curr_win_x, curr_win_y, curr_win_width, curr_win_height, A | |
; loop to check which screen the current active window shall be within | |
Loop, %MonitorCount% | |
{ | |
SysGet, Monitor, Monitor, %A_Index% | |
; care only the top-left position of the window | |
if (curr_win_x >= MonitorLeft && curr_win_x < MonitorRight && curr_win_y >= MonitorTop && curr_win_y < MonitorBottom) | |
{ | |
target_monitor := A_Index | |
;MsgBox, Detect active window is at monitor %A_Index% | |
;MsgBox, %MonitorLeft%, %MonitorRight%, %MonitorTop%, %MonitorBottom% | |
break | |
} | |
} | |
; bound check the target_monitor | |
if (target_monitor < 1 && target_monitor > MonitorCount) | |
{ | |
MsgBox, %target_monitor% is out of bound of %MonitorCount% | |
return | |
} | |
SysGet, Monitor, Monitor, %target_monitor% | |
WinMove, A,, MonitorLeft, MonitorTop, (MonitorRight-MonitorLeft), (MonitorBottom-MonitorTop)/2.0 | |
return | |
; ---------- | |
; Move window down (Windows + Shift + DOWN) | |
+#Down:: | |
target_monitor := 2 | |
SysGet, MonitorCount, MonitorCount | |
; get current active window | |
WinGetPos, curr_win_x, curr_win_y, curr_win_width, curr_win_height, A | |
; loop to check which screen the current active window shall be within | |
Loop, %MonitorCount% | |
{ | |
SysGet, Monitor, Monitor, %A_Index% | |
; care only the top-left position of the window | |
if (curr_win_x >= MonitorLeft && curr_win_x < MonitorRight && curr_win_y >= MonitorTop && curr_win_y < MonitorBottom) | |
{ | |
target_monitor := A_Index | |
;MsgBox, Detect active window is at monitor %A_Index% | |
;MsgBox, %MonitorLeft%, %MonitorRight%, %MonitorTop%, %MonitorBottom% | |
break | |
} | |
} | |
; bound check the target_monitor | |
if (target_monitor < 1 && target_monitor > MonitorCount) | |
{ | |
MsgBox, %target_monitor% is out of bound of %MonitorCount% | |
return | |
} | |
SysGet, Monitor, Monitor, %target_monitor% | |
WinMove, A,, MonitorLeft, (MonitorBottom-MonitorTop)/2.0 + MonitorTop, (MonitorRight-MonitorLeft), (MonitorBottom-MonitorTop)/2.0 | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment