Mit dem folgenden Skript kann man herausfinden, auf welchem Monitor sich der Mauscursor befindet:
Spoiler anzeigen
Func _GetMouseInfo()
;Returns the screen number on which the actual mouse cursor is
;Call: _GetMouseInfo()
;Don't miss to include the Func_GetMonitorInfo.au3 (#include "Func_GetMonitorInfo.au3")
$MousePos = MouseGetPos()
$NrOfScreens = _GetMonitorInfo("Nr","")
For $i = 1 To $NrOfScreens
If $MousePos[0] >= _GetMonitorInfo("PosX",$i) AND ($MousePos[0] <= _GetMonitorInfo("PosX",$i) + _GetMonitorInfo("ResX",$i)) AND $MousePos[1] >= _GetMonitorInfo("PosY",$i) AND ($MousePos[1] <= _GetMonitorInfo("PosY",$i) + _GetMonitorInfo("ResY",$i)) Then Return $i
;Checks on which Screen the Mousecursor is
Next
EndFunc
Dazu wird noch die folgende Funktion benötigt:
Spoiler anzeigen
Func _GetMonitorInfo($Typ, $Nr)
;Returns some informations about your screens
;Call: _GetMonitorInfo("Typ", "Nr")
;Possible Values for "Typ": "Nr" / "ResX" / "ResY" / "PosX" / "PosY"
;If "Typ" = "Nr", then the Number of asked Screen will be ignored!
;Nr = Number of asked Screen
Local $NrOfMonitors, $ResolutionX[32], $ResolutionY[32], $PositionX[32], $PositionY[32]
Local $cbMonitorEnumProc = DllCallbackRegister("MonitorEnumProc", "ubyte", "ptr;ptr;ptr;int")
If @error Then Return SetError(1, 0, False)
Local $strctCount = DllStructCreate("uint Count;uint Width[12];uint Height[12];int left[12];int top[12]")
If @error Then Return SetError(2, @error, False)
Local $iCount
DllStructSetData($strctCount, "Count", 0)
$Ret = DllCall("User32.dll", "ubyte","EnumDisplayMonitors","ptr", 0,"ptr", 0, "ptr", DllCallbackGetPtr($cbMonitorEnumProc), "ptr", DllStructGetPtr($strctCount))
If @error Or $Ret[0] = 0 Then Return SetError(3, @error, False)
DllCallbackFree($cbMonitorEnumProc)
$iCount = Int(DllStructGetData($strctCount, "Count"))
Local $aMonitors[$iCount+1][4] = [[$iCount]]
For $i = 1 To $iCount
$aMonitors[$i][0] = Int(DllStructGetData($strctCount, "Width",$i))
$aMonitors[$i][1] = Int(DllStructGetData($strctCount, "Height",$i))
$aMonitors[$i][2] = Int(DllStructGetData($strctCount, "left",$i))
$aMonitors[$i][3] = Int(DllStructGetData($strctCount, "top",$i))
Next
If Not @error Then
$NrOfMonitors = $aMonitors[0][0]
For $i = 1 To $NrOfMonitors
$ResolutionX[$i] = $aMonitors[$i][0]
$ResolutionY[$i] = $aMonitors[$i][1]
$PositionX[$i] = $aMonitors[$i][2]
$PositionY[$i] = $aMonitors[$i][3]
Next
EndIf
Select
Case $Typ="Nr"
Return $NrOfMonitors
Case $Typ="ResX"
Return $ResolutionX[$Nr]
Case $Typ="ResY"
Return $ResolutionY[$Nr]
Case $Typ="PosX"
Return $PositionX[$Nr]
Case $Typ="PosY"
Return $PositionY[$Nr]
EndSelect
EndFunc
Func MonitorEnumProc($hMonitor, $hdcMonitor, $lprcMonitor, $dwData)
Local $strctRECT = DllStructCreate("long left;long top;long right;long bottom", $lprcMonitor)
Local $strctCount = DllStructCreate("uint Count;uint Width[12];uint Height[12];int left[12];int top[12]", $dwData)
Local $iNumber = DllStructGetData($strctCount, "Count")
Local $Height = Int(DllStructGetData($strctRECT, "bottom"))-Int(DllStructGetData($strctRECT, "top"))
Local $Width = Int(DllStructGetData($strctRECT, "right"))-Int(DllStructGetData($strctRECT, "left"))
DllStructSetData($strctCount, "Width", $Width, $iNumber+1)
DllStructSetData($strctCount, "Height", $Height, $iNumber+1)
DllStructSetData($strctCount, "left", Int(DllStructGetData($strctRECT, "left")), $iNumber+1)
DllStructSetData($strctCount, "top", Int(DllStructGetData($strctRECT, "top")), $iNumber+1)
DllStructSetData($strctCount, "Count", $iNumber+1)
Return True
EndFunc