Ниже вы получите именно это. Индекс монитора в AHK, чтобы вы могли ссылаться на него.
GetFocusWindowMonitorIndex(){
;Get number of monitor
SysGet, monCount, MonitorCount
;Counter
i := 1
;Iterate through each monitor
Loop %monCount%{
;Get Monitor working area
SysGet, workArea, Monitor, %i%
;Get the position of the focus window
WinGetPos, X, Y, , , A
;Check if the focus window in on the current monitor index
if (X >= workAreaLeft && X < workAreaRight && Y >= workAreaTop && Y < workAreaBottom ){
;Return the monitor index since its within that monitors borders.
return i
}
;Next monitor
i := i + 1
}
}
Примечание. Ниже приведена измененная версия, в которой окно передается в качестве аргумента, а не по умолчанию; окно фокуса
GetFocusWindowMonitorIndex(thisWindow){
;Get number of monitor
SysGet, monCount, MonitorCount
;Counter
i := 1
;Iterate through each monitor
Loop %monCount%{
;Get Monitor working area
SysGet, workArea, Monitor, %i%
;Get the position of the focus window
WinGetPos, X, Y, , , %thisWindow%
;Check if the focus window in on the current monitor index
if (X >= workAreaLeft && X < workAreaRight && Y >= workAreaTop && Y < workAreaBottom ){
;Return the monitor index since it's within that monitors borders.
return i
}
;Next monitor
i := i + 1
}
}
Даже если это поможет еще одному человеку, я назову это победой.
РЕДАКТИРОВАТЬ:
Если вам нужна рабочая зона (за исключением tarkbar из рабочей области) используйте эти функции.
GetFocusWindowMonitorIndex(){
;Get number of monitor
SysGet, monCount, MonitorCount
;Counter
i := 1
;Iterate through each monitor
Loop %monCount%{
;Get Monitor working area
SysGet, workArea, MonitorWorkArea , %i%
;Get the position of the focus window
WinGetPos, X, Y, , , A
;Check if the focus window in on the current monitor index
if (X >= workAreaLeft && X < workAreaRight && Y >= workAreaTop && Y < workAreaBottom ){
;Return the monitor index since its within that monitors borders.
return i
}
;Next monitor
i := i + 1
}
}