From 778f69e14df2d9090a341e67a67bc91b93fcc174 Mon Sep 17 00:00:00 2001 From: yu <191972707@qq.com> Date: Thu, 29 Oct 2026 15:26:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A1=8C=E9=9D=A2=E6=8B=BE=E5=8F=96?= =?UTF-8?q?=E4=B8=8B=E9=92=BB=E5=88=B0=E5=8C=85=E5=90=AB=E9=BC=A0=E6=A0=87?= =?UTF-8?q?=E7=82=B9=E7=9A=84=E6=9C=80=E5=B0=8F=E6=8E=A7=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=91=BD=E4=B8=AD=E5=AE=B9=E5=99=A8=E7=BA=A7?= =?UTF-8?q?=E5=A4=A7=E5=85=83=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/desktop-picker.ps1 | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/resources/desktop-picker.ps1 b/resources/desktop-picker.ps1 index b4ab039..6f4c641 100644 --- a/resources/desktop-picker.ps1 +++ b/resources/desktop-picker.ps1 @@ -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 }