Send-Keys to an non active Window

Oct 22, 2014 at 12:03 PM
Hello,

i am using WASP since today, and ill try this:

Using WASP which is sending Send-Keys commands to notepad++; but if click on another application the Send-Keys commands will be send to application which i have opened.

Is there a function in WASP where i can send the Send-Keys commands to notepad++ when its not active?

My Script:
ipmo .\WASP.dll
$bla = $false
try {            
$ActiveHandle = [UserWindows]::GetForegroundWindow()            
$FindProg = Get-Process | Where-Object {$_.Name -eq 'notepad++'}
    [Microsoft.VisualBasic.Interaction]::AppActivate($FindProg.ID)          
$FindProg | Select ProcessName, @{Name="AppTitle";Expression= {($_.MainWindowTitle)}}            
} catch {            
 Write-Error "Failed to get active Window details. More Info: $_"            
}
while($bla -eq $false){
Select-Window $FindProg | Send-Keys ('Hello')
Sleep -Seconds 2
Select-Window $FindProg | Send-Keys ('Hello')
Sleep -Seconds 2
Select-Window $FindProg | Send-Keys ('Hello')
Sleep -Seconds 2
}
Coordinator
Oct 22, 2014 at 3:13 PM
No. It's not possible, in windows (for your protection).

You can't simulate input to an app that doesn't have focus -- because that would allow malicious apps to do anything they wanted.

Even when apps fully support UI Automation, and implement the "Value" field, invoking the SetValue member will require focus. See this example, for instance:
http://msdn.microsoft.com/en-us/library/ms750582%28v=vs.110%29.aspx