-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertical snap.ahk
More file actions
77 lines (61 loc) · 2.38 KB
/
Vertical snap.ahk
File metadata and controls
77 lines (61 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; dir 0 = top part
; dir 1 = bottom part
; size 0 = half of screen
; size 1 = third of screen
ResizeWin(dir = 1, size = 0)
{
WinGet activeWin, ID, A
activeMon := GetMonitorIndexFromWindow(activeWin)
SysGet, MonitorWorkArea, MonitorWorkArea, %activeMon%
w := MonitorWorkAreaRight - MonitorWorkAreaLeft
if (size == 0)
h := (MonitorWorkAreaBottom - MonitorWorkAreaTop)/2
else
h := (MonitorWorkAreaBottom - MonitorWorkAreaTop)/3
if (dir == 1)
t := MonitorWorkAreaBottom - h
else
t := MonitorWorkAreaTop
WinMove,A,,%MonitorWorkAreaLeft%,%t%,%w%,%h%
}
GetMonitorIndexFromWindow(windowHandle)
{
; Starts with 1.
monitorIndex := 1
VarSetCapacity(monitorInfo, 40)
NumPut(40, monitorInfo)
if (monitorHandle := DllCall("MonitorFromWindow", "uint", windowHandle, "uint", 0x2))
&& DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo)
{
monitorLeft := NumGet(monitorInfo, 4, "Int")
monitorTop := NumGet(monitorInfo, 8, "Int")
monitorRight := NumGet(monitorInfo, 12, "Int")
monitorBottom := NumGet(monitorInfo, 16, "Int")
workLeft := NumGet(monitorInfo, 20, "Int")
workTop := NumGet(monitorInfo, 24, "Int")
workRight := NumGet(monitorInfo, 28, "Int")
workBottom := NumGet(monitorInfo, 32, "Int")
isPrimary := NumGet(monitorInfo, 36, "Int") & 1
SysGet, monitorCount, MonitorCount
Loop, %monitorCount%
{
SysGet, tempMon, Monitor, %A_Index%
; Compare location to determine the monitor index.
if ((monitorLeft = tempMonLeft) and (monitorTop = tempMonTop)
and (monitorRight = tempMonRight) and (monitorBottom = tempMonBottom))
{
monitorIndex := A_Index
break
}
}
}
return %monitorIndex%
}
#!Up::ResizeWin(0)
#!Down::ResizeWin(1)
^#!Up::ResizeWin(0,1)
^#!Down::ResizeWin(1,1)