AutomationFocusChangedEventHandler:事件未在powershell中触发
我正在使用powershell脚本检测焦点更改,这是我的代码AutomationFocusChangedEventHandler:事件未在powershell中触发,powershell,microsoft-ui-automation,Powershell,Microsoft Ui Automation,我正在使用powershell脚本检测焦点更改,这是我的代码 start calc Write-Host "Loading MS UIA assemblies" [void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationClient") [void][System.Reflection.Assembly]::LoadWithPartialName("UIAutoma
start calc
Write-Host "Loading MS UIA assemblies"
[void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationClient")
[void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationTypes")
[void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationProvider")
[void][System.Reflection.Assembly]::LoadWithPartialName("UIAutomationClientsideProviders")
try
{
# WORKAROUND: There is a weird bug: first call fails ...
[Windows.Automation.ClientSettings]::RegisterClientSideProviderAssembly([UIAutomationClientsideProviders.UIAutomationClientSideProviders].Assembly.GetName())
}
catch {}
# ... second call succeeds:
[Windows.Automation.ClientSettings]::RegisterClientSideProviderAssembly([UIAutomationClientsideProviders.UIAutomationClientSideProviders].Assembly.GetName())
$focusedElem = [Windows.Automation.AutomationElement]::FocusedElement #this one work fine
Write-Host "name: " $focusedElem.Current.Name
Write-Host "ControlType: " $focusedElem.Current.ControlType
Write-Host "ProcessId: " $focusedElem.Current.ProcessId
$onFocusChange = { # this dose not fired !!!!
param([Sytem.Object]$src, [Windows.Automation.AutomationFocusChangedEventArgs]$e)
start notepad
}
$focusChangeHandler = [Windows.Automation.AutomationFocusChangedEventHandler]($onFocusChange)
[Windows.Automation.Automation]::AddAutomationFocusChangedEventHandler($focusChangeHandler)
Start-Sleep -Seconds 5 #durring this sleep i change the focused window, but nothing happen :(
[Windows.Automation.Automation]:: RemoveAutomationFocusChangedEventHandler($focusChangeHandler)
知道为什么这个脚本不起作用吗,或者知道如何在没有外部工具的情况下监视powershell中的焦点更改吗