I only had 2 monitors (Left [Primary] & Right [Secondary]) to test this. Hope it works!
Code: Select all
#SingleInstance, Force
CoordMode, Mouse, Screen
F1::
MouseGetPos, MouseX, MouseY, MouseWin, MouseCtl
MouseMon := GetMonitorAt(MouseX, MouseY)
WinGet, List, List,,, Program Manager
Loop, % List {
this_id := List%A_Index%
If (GetMonitorIndexFromWindow(this_id) = MouseMon) {
WinMinimize, ahk_id %this_id%
}
}
return
GetMonitorAt(X, Y, Default := 1){
SysGet, MonCount, MonitorCount
Loop, % MonCount {
SysGet, Mon, Monitor, % A_Index
If (X >= MonLeft && X <= MonRight && Y >= MonTop && Y <= MonBottom) {
return A_Index
}
}
return Default
}
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
}