Tag Archives: InvokedEvent

Daily automation: registering user’s clicks


Have you never desired to write all the actions the user of your application performed? What a pity, there’s no embedded logging in our application… Hey, no problem here! The today’s sample demonstrates how to write down all button clicks.

Task: register all the clicks that the user done during the session.

Requirements: use the module for dumping all the button click events happened after the application started.

Solution: for simplicity sake, let’s start Calculator and choose the Standard mode. Close the application and run the following code:

ipmo [path]\UIAutomation.dll;

# use the Get-UIAControlDescendants cmdlet to collect all the visible buttons
# use the Register-UIAInvokedEvent cmdlet to assign an event action to each button
Start-Process calc -PassThru | `
Get-UIAWindow | `
Get-UIAControlDescendants -ControlType Button | `
Register-UIAInvokedEvent -EventAction {param($src) "$($src.Current.Name) clicked" >> $env:TEMP\calc.log;}

After the code is processed by PowerShell, the file will contain all key pressings.

Advertisements
%d bloggers like this: