fix: 桌面拾取下钻到包含鼠标点的最小控件,修复命中容器级大元素
This commit is contained in:
parent
8b0004bf72
commit
778f69e14d
@ -15,6 +15,29 @@ if ($Mode -eq "windows") {
|
||||
exit 0
|
||||
}
|
||||
|
||||
function Get-DeepestAtPoint([double]$px, [double]$py) {
|
||||
$point = New-Object System.Windows.Automation.Point($px, $py)
|
||||
$cur = [System.Windows.Automation.AutomationElement]::FromPoint($point)
|
||||
if (-not $cur) { return $null }
|
||||
for ($depth = 0; $depth -lt 30; $depth++) {
|
||||
$children = $cur.FindAll([System.Windows.Automation.TreeScope]::Children, [System.Windows.Automation.Condition]::TrueCondition)
|
||||
$next = $null
|
||||
$nextArea = [double]::MaxValue
|
||||
foreach ($c in $children) {
|
||||
try {
|
||||
$r = $c.Current.BoundingRectangle
|
||||
if ($r.Width -gt 0 -and $r.Height -gt 0 -and $px -ge $r.X -and $px -le ($r.X + $r.Width) -and $py -ge $r.Y -and $py -le ($r.Y + $r.Height)) {
|
||||
$area = $r.Width * $r.Height
|
||||
if ($area -lt $nextArea) { $next = $c; $nextArea = $area }
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
if (-not $next) { break }
|
||||
$cur = $next
|
||||
}
|
||||
return $cur
|
||||
}
|
||||
|
||||
$form = New-Object System.Windows.Forms.Form
|
||||
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::None
|
||||
$form.TopMost = $true
|
||||
@ -35,9 +58,7 @@ $result = $null
|
||||
while ($true) {
|
||||
$ptX = [System.Windows.Forms.Cursor]::Position.X
|
||||
$ptY = [System.Windows.Forms.Cursor]::Position.Y
|
||||
$point = New-Object System.Windows.Automation.Point($ptX, $ptY)
|
||||
$el = $null
|
||||
try { $el = [System.Windows.Automation.AutomationElement]::FromPoint($point) } catch {}
|
||||
$el = Get-DeepestAtPoint $ptX $ptY
|
||||
$down = ([RpaPick.PickW32]::GetAsyncKeyState(32) -band 0x8000) -ne 0
|
||||
$esc = ([RpaPick.PickW32]::GetAsyncKeyState(27) -band 0x8000) -ne 0
|
||||
if ($esc) { break }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user