gpt4 book ai didi

autohotkey - 确定焦点窗口在哪个监视器上?

转载 作者:行者123 更新时间:2023-12-03 17:12:31 25 4
gpt4 key购买 nike

用于确定焦点窗口在哪个监视器上的小型 AHK 函数。

我正在编写一个脚本,该脚本需要焦点窗口所在监视器的上下文。我找到了很多解决方案,但没有一个太容易遵循,或者比需要的更复杂。

最佳答案

下面会告诉你。 AHK 中的监视器索引,因此您可以引用它。

GetFocusWindowMonitorIndex(){
;Get number of monitor
SysGet, monCount, MonitorCount

;Iterate through each monitor
Loop %monCount%{
;Get Monitor working area
SysGet, workArea, Monitor, % A_Index

;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 % A_Index
}
}
}
注意下面是一个修改版本,其中窗口作为参数传递,而不是默认值;焦点窗口
GetFocusWindowMonitorIndex(thisWindow){
;Get number of monitor
SysGet, monCount, MonitorCount

;Iterate through each monitor
Loop %monCount%{
;Get Monitor working area
SysGet, workArea, Monitor, % A_Index

;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 % A_Index
}
}
}
即使这能帮助更多人,我也会称其为胜利。
编辑:
如果您需要工作区(从工作区中排除 tarkbar),请使用此功能。
GetFocusWindowMonitorIndex(){
;Get number of monitor
SysGet, monCount, MonitorCount

;Iterate through each monitor
Loop %monCount%{
;Get Monitor working area
SysGet, workArea, MonitorWorkArea , % A_Index

;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 % A_Index
}
}
}

关于autohotkey - 确定焦点窗口在哪个监视器上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59883798/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com