UIAControlKeys "{SPACE}" does 3 spaces

May 1, 2014 at 10:19 PM
Edited May 1, 2014 at 11:01 PM

I'm having an issue where when I use

Set-UIAControlKeys " {SPACE} "

The automation doesn't recognize this function, but I used this fuction not long ago so I don't know what's going on.

Here's my code:
$testPath = Split-Path -parent $MyInvocation.MyCommand.Definition

# Import req'd libraries
Import-Module -Name "$testPath\UIAutomation\UIAutomation.dll"

[UIAutomation.Preferences]::Highlight = $false

$WinWindow = Get-UIAWindow -Title "*TextPad*"
$WinWindow | Set-UIAFocus | Out-Null
Start-Sleep -s 1

for ($i = 0 ; $i -lt 500 ; $i + +) {   #should be plus signs instead of the #43 things)
    $WinWindow | Set-UIAControlKeys "{TAB}"
    Start-Sleep -s 1
    $WinWindow | Set-UIAControlKeys "{SPACE}"
    Start-Sleep -s 1
May 6, 2014 at 7:13 PM
I can tell you what one problem is.
This is about Powershell syntax, not specific to UIAutomation.

You need to have no spaces between the variable and the two plus signs in the 'for' statement.
for ($i = 0 ; $i -lt 500 ; $i + +) { 
should be
for ($i = 0 ; $i -lt 500 ; $i++) { 
May 10, 2014 at 1:23 PM
thank you joespr for the answer.
If you CronusIX suffer the issue until now, there is a newer way to send keys.

All old cmdlets are supported unless they are mentioned obsolete (the Set-UIAControlKeys cmdlet is supported), however the new way is better, tested with a great number of users of the InputSimulator framework and as I think is more useful.
May 12, 2014 at 2:57 PM
Thank you. That was done for clarification here on the boards because the forum here was turning the $i++ into a string of "43" so I put spaces so my for loop would look correct.

Thank you for the help I'll look into it.
However I did find a work around to send a space that works very well

if you add this as part of your setup:
[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
And then use this to send a space:
[System.Windows.Forms.SendKeys]::SendWait(" ")
It works just fine. Thanks for the help.