fix: 点击前检测最小化/屏幕外窗口并自动还原,修复 -32000 坐标点击落空
This commit is contained in:
parent
093fc302fa
commit
06981dfff3
@ -167,7 +167,37 @@ try {
|
||||
} catch { $el = $null }
|
||||
if ($null -eq $el) { Write-Output "JSON_NOT_FOUND"; exit 0 }
|
||||
$rect = $el.Current.BoundingRectangle
|
||||
$offscreen = $el.Current.IsOffscreen -or $rect.Width -le 0 -or $rect.Height -le 0
|
||||
Add-RpaUser32
|
||||
$vsX = [WinRpa.RpaUser32Click]::GetSystemMetrics(76)
|
||||
$vsY = [WinRpa.RpaUser32Click]::GetSystemMetrics(77)
|
||||
$vsW = [WinRpa.RpaUser32Click]::GetSystemMetrics(78)
|
||||
$vsH = [WinRpa.RpaUser32Click]::GetSystemMetrics(79)
|
||||
$inVs = ($rect.X -ge $vsX) -and ($rect.Y -ge $vsY) -and (($rect.X + $rect.Width) -le ($vsX + $vsW)) -and (($rect.Y + $rect.Height) -le ($vsY + $vsH))
|
||||
$offscreen = $el.Current.IsOffscreen -or $rect.Width -le 0 -or $rect.Height -le 0 -or (-not $inVs)
|
||||
if ($offscreen) {
|
||||
# 窗口可能被最小化或移出屏幕:还原并移回可视区后重取坐标
|
||||
$walker0 = [System.Windows.Automation.TreeWalker]::ControlViewWalker
|
||||
$anc0 = $el
|
||||
$topHwnd = [IntPtr]::Zero
|
||||
while ($null -ne $anc0) {
|
||||
$h0 = $anc0.Current.NativeWindowHandle
|
||||
if ($h0 -ne 0) { $topHwnd = [IntPtr]$h0; break }
|
||||
$anc0 = $walker0.GetParent($anc0)
|
||||
}
|
||||
if ($topHwnd -ne [IntPtr]::Zero) {
|
||||
[WinRpa.RpaUser32Click]::ShowWindow($topHwnd, 9) | Out-Null
|
||||
Start-Sleep -Milliseconds 600
|
||||
$sw3 = [WinRpa.RpaUser32Click]::GetSystemMetrics(0)
|
||||
$sh3 = [WinRpa.RpaUser32Click]::GetSystemMetrics(1)
|
||||
$w3 = [Math]::Min(1400, $sw3 - 120)
|
||||
$h3 = [Math]::Min(820, $sh3 - 120)
|
||||
[WinRpa.RpaUser32Click]::SetWindowPos($topHwnd, [IntPtr]::Zero, 60, 60, $w3, $h3, 0x0040) | Out-Null
|
||||
Start-Sleep -Milliseconds 600
|
||||
$rect = $el.Current.BoundingRectangle
|
||||
$inVs = ($rect.X -ge $vsX) -and ($rect.Y -ge $vsY) -and (($rect.X + $rect.Width) -le ($vsX + $vsW)) -and (($rect.Y + $rect.Height) -le ($vsY + $vsH))
|
||||
$offscreen = $el.Current.IsOffscreen -or $rect.Width -le 0 -or $rect.Height -le 0 -or (-not $inVs)
|
||||
}
|
||||
}
|
||||
$method = "coordinate_click"
|
||||
$ok = $false
|
||||
if (-not $offscreen) {
|
||||
@ -358,3 +388,4 @@ register("Element_WaitElementGround", waitElementGround);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user