本帖最后由 tubaba 于 2024-3-14 09:26 编辑
有这几个API可用
Local $tagPOINT = "struct; long X;long Y; endstruct"
Local $tPoint = DllStructCreate($tagPOINT)
DllStructSetData($tPoint, 'X', MouseGetPos(0)) ;当前鼠标X
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : MouseGetPos(0) = ' & MouseGetPos(0) & @CRLF & '>Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ') SystemTime: ' & @hour & ':' & @min & ':' & @sec & @CRLF) ;### Debug Console
DllStructSetData($tPoint, 'Y', MouseGetPos(1)) ;当前鼠标Y
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : MouseGetPos(1) = ' & MouseGetPos(1) & @CRLF & '>Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ') SystemTime: ' & @hour & ':' & @min & ':' & @sec & @CRLF) ;### Debug Console
Local $aRet = DllCall('user32.dll', 'hwnd', 'MonitorFromPoint', 'STRUCT', $tPoint, 'DWORD', 0)
If $aRet[0] <> 0 Then
Local $gMonitorInfo = DllStructCreate('dword;long[4];long[4];dword;wchar[32]')
DllStructSetData($gMonitorInfo, 1, DllStructGetSize($gMonitorInfo))
DllCall('user32.dll', 'bool', 'GetMonitorInfoW', 'handle', $aRet[0], 'ptr', DllStructGetPtr($gMonitorInfo))
Local $aMonitor[4]
For $i = 1 To 4
$aMonitor[$i - 1] = DllStructGetData($gMonitorInfo, 3, $i)
Next
$aMonitor[2] -= $aMonitor[0];当前显示器的显示宽度
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aMonitor[2] = ' & $aMonitor[2] & @CRLF & '>Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ') SystemTime: ' & @hour & ':' & @min & ':' & @sec & @CRLF) ;### Debug Console
$aMonitor[3] -= $aMonitor[1];当前显示器的显示高度
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aMonitor[3] = ' & $aMonitor[3] & @CRLF & '>Error code: ' & @error & ' Extended code: ' & @extended & ' (0x' & Hex(@extended) & ') SystemTime: ' & @hour & ':' & @min & ':' & @sec & @CRLF) ;### Debug Console
EndIf
以下是测试结果,主显示器显示范围1920*1050,副显示器1600*870鼠标在副显示器范围内
副显示器在主显示器的左边时
@@ Debug(4) : MouseGetPos(0) = -992
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:08:27
@@ Debug(6) : MouseGetPos(1) = 324
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:08:27
@@ Debug(17) : $aMonitor[2] = 1600
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:08:27
@@ Debug(19) : $aMonitor[3] = 870
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:08:27
副显示器在主显示器的右边时
@@ Debug(4) : MouseGetPos(0) = 2497
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:16:05
@@ Debug(6) : MouseGetPos(1) = 509
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:16:05
@@ Debug(17) : $aMonitor[2] = 1600
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:16:05
@@ Debug(19) : $aMonitor[3] = 870
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:16:05
副显示器在主显示器的上边时
@@ Debug(4) : MouseGetPos(0) = 1243
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:14:01
@@ Debug(6) : MouseGetPos(1) = -442
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:14:01
@@ Debug(17) : $aMonitor[2] = 1600
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:14:01
@@ Debug(19) : $aMonitor[3] = 870
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:14:01
副显示器在主显示器的下边时
@@ Debug(4) : MouseGetPos(0) = 1087
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:15:15
@@ Debug(6) : MouseGetPos(1) = 1512
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:15:15
@@ Debug(17) : $aMonitor[2] = 1600
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:15:15
@@ Debug(19) : $aMonitor[3] = 870
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:15:15
鼠标在主显示器范围内
@@ Debug(4) : MouseGetPos(0) = 976
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:18:07
@@ Debug(6) : MouseGetPos(1) = 600
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:18:07
@@ Debug(17) : $aMonitor[2] = 1920
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:18:07
@@ Debug(19) : $aMonitor[3] = 1050
>Error code: 0 Extended code: 0 (0x00000000) SystemTime: 09:18:07
|