微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AutomationFocusChangedEventHandler:PowerShell中未触发事件剂量

如何解决AutomationFocusChangedEventHandler:PowerShell中未触发事件剂量

我正在准备使用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中没有外部工具的焦点更改?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。