MenuOpened and MenuClosed events inform that a menu item has been clicked or activated from keyboard.
Their work is demostrated in the following samples:
# an ArrayList for storing names of items clicked and for event ids
$global:annals = New-Object System.Collections.ArrayList;
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAMenuItem | Register-UIAMenuOpenedEvent -EventAction { param($src, $e) $global:annals.Add($src.Current.Name); $global:annals.Add($e.EventId); }
Get-UIAMenuItem -Name view | Invoke-UIAMenuItemExpand;
Get-UIAMenuItem -Name help | Invoke-UIAMenuItemExpand;
Get-UIAMenuItem -Name edit | Invoke-UIAMenuItemExpand;
# events are a bit slow
sleep -Seconds 1;
$global:annals;
Here we register MenuOpened events as well as menuClosed events:
$global:annals = New-Object System.Collections.ArrayList;
Start-Process calc -PassThru | Get-UIAWindow | Get-UIAMenuItem | Register-UIAMenuOpenedEvent -EventAction { param($src, $e) $global:annals.Add("opened:"); $global:annals.Add($src.Current.Name); $global:annals.Add($e.EventId); };
Get-UIAMenuItem | Register-UIAMenuClosedEvent -EventAction { param($src, $e) $global:annals.Add("closed:"); $global:annals.Add($src.Current.Name); $global:annals.Add($src.Cached.Name); $global:annals.Add($e.EventId); };
Get-UIAMenuItem -Name view | Invoke-UIAMenuItemExpand;
Get-UIAMenuItem -Name help | Invoke-UIAMenuItemExpand;
Get-UIAMenuItem -Name edit | Invoke-UIAMenuItemExpand;
sleep -Seconds 2;
$global:annals;
Note that no names of closed menu items are provided.

Last edited Jan 21, 2013 at 6:50 PM by xinliu, version 3

Comments

No comments yet.