The Keyboard property holder exposes methods that are similar to SendKeys. UIAutomation tries to set the focus on a control and thereafter puts keys on it.
The Keyboard property exposes several method of
# just any text
# any character
# these methods allow you to press specific keys like Control,
These method consume the [WindowsInput.Native.VirtualKeyCode] enumeration for both alphanumeric characters and for control keys like RETURN.
You can use the methods on controls that accept input like text boxes as well as controls that accept input for the window they are in, for example:
$wnd = Start-Process calc -PassThru | Get-UiaWindow
$btn1 = Get-UiaButton 1
# sending "222" to the window
# sending "333" to the button 1
As can be seen, if controls accept keyboard input, even button 1 accepts number 3. :)
To illustrate the use of KeyDown, KeyPress and KeyUp method, there is the following code that types "AAA" to notepad.exe:
$wnd = Start-Process notepad -PassThru | Get-UiaWindow
Without lines that works with the Shift key, we would see "aaa" instead of "AAA".
These method are priceless when working with controls that don't support pattern.
Please refer to the
page for the list of key codes.