19 lines
901 B
PowerShell
19 lines
901 B
PowerShell
# Route posted mouse messages to the actual child control in the target window.
|
|
# Screen hit testing is deliberately not used: another window may cover the target.
|
|
function Resolve-InputWindow([IntPtr]$root, [int]$screenX, [int]$screenY) {
|
|
$current = $root
|
|
for ($depth = 0; $depth -lt 32; $depth++) {
|
|
$point = New-Object OCUWin32+POINT
|
|
$point.X = $screenX
|
|
$point.Y = $screenY
|
|
if (-not [OCUWin32]::ScreenToClient($current, [ref]$point)) {
|
|
throw 'The target window is no longer available; observe again before acting.'
|
|
}
|
|
# Skip invisible, disabled and transparent child windows.
|
|
$child = [OCUWin32]::ChildWindowFromPointEx($current, $point, 7)
|
|
if ($child -eq [IntPtr]::Zero -or $child -eq $current) { return $current }
|
|
$current = $child
|
|
}
|
|
throw 'Target child window nesting exceeded the input limit.'
|
|
}
|