我的解决办法是使用<代码>MonitorGetCount和MonitorGet
,以检查协调是否适合监测的界限。
(AHK v2) 申报辅助人员的职能:
ScreenUtil_GetMonitorInfoOfActiveWindow(&monitorIndex, &left, &top, &right, &bottom){
WinGetPos(&mx, &my, &mw, &mh, "A")
ScreenUtil_GetMonitorInfoAtPoint(mx + mw//2, my + mh//2, &monitorIndex, &left, &top, &right, &bottom)
}
ScreenUtil_GetMonitorInfoAtMousePointer(&monitorIndex, &left, &top, &right, &bottom){
CoordMode "Mouse", "Screen"
MouseGetPos(&mx, &my)
ScreenUtil_GetMonitorInfoAtPoint(mx, my, &monitorIndex, &left, &top, &right, &bottom)
}
ScreenUtil_GetMonitorInfoAtPoint(x, y, &monitorIndex, &left, &top, &right, &bottom){
loop MonitorGetCount(){
MonitorGet(A_Index, &_left, &_top, &_right, &_bottom)
if(_left <= x && x <= _right && _top <= y && y <= _bottom){
monitorIndex := A_Index
left := _left
top := _top
right := _right
bottom := _bottom
return
}
}
throw Error("Cannot find a monitor that encloses the point!")
}
然后,视你如何界定“主动监测”:
- To get info of the monitor which the active window resides in:
ScreenUtil_GetMonitorInfoOfActiveWindow(&monitorIndex, &left, &top, &right, &bottom)
MsgBox("Width: " right - left "`nHeight: " bottom - top)
- To get info of the monitor which the mouse pointer resides in :
ScreenUtil_GetMonitorInfoAtMousePointer(&monitorIndex, &left, &top, &right, &bottom)
MsgBox("Width: " right - left "`nHeight: " bottom - top)
(测试综合文字)
#Requires AutoHotkey v2.0
!1::{
ScreenUtil_GetMonitorInfoOfActiveWindow(&monitorIndex, &left, &top, &right, &bottom)
MsgBox("Width: " right - left "`nHeight: " bottom - top)
}
!2::{
ScreenUtil_GetMonitorInfoAtMousePointer(&monitorIndex, &left, &top, &right, &bottom)
MsgBox("Width: " right - left "`nHeight: " bottom - top)
}
ScreenUtil_GetMonitorInfoOfActiveWindow(&monitorIndex, &left, &top, &right, &bottom){
WinGetPos(&mx, &my, &mw, &mh, "A")
ScreenUtil_GetMonitorInfoAtPoint(mx + mw//2, my + mh//2, &monitorIndex, &left, &top, &right, &bottom)
}
ScreenUtil_GetMonitorInfoAtMousePointer(&monitorIndex, &left, &top, &right, &bottom){
CoordMode "Mouse", "Screen"
MouseGetPos(&mx, &my)
ScreenUtil_GetMonitorInfoAtPoint(mx, my, &monitorIndex, &left, &top, &right, &bottom)
}
ScreenUtil_GetMonitorInfoAtPoint(x, y, &monitorIndex, &left, &top, &right, &bottom){
loop MonitorGetCount(){
MonitorGet(A_Index, &_left, &_top, &_right, &_bottom)
if(_left <= x && x <= _right && _top <= y && y <= _bottom){
monitorIndex := A_Index
left := _left
top := _top
right := _right
bottom := _bottom
return
}
}
throw Error("Cannot find a monitor that encloses the point!")
}