Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AutomationFocusChangedEventHandler:事件未在powershell中触发_Powershell_Microsoft Ui Automation - Fatal编程技术网

AutomationFocusChangedEventHandler:事件未在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

我正在使用powershell脚本检测焦点更改,这是我的代码

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中的焦点更改吗