title: Sending keys to an open windows in PowerShell
body: <p>I made a program that opens a certain program, then <kbd>Ctrl</kbd>+<kbd>C</kbd> it after x amount of time.</p>
  
  <p>I am now using this <code>[System.Windows.Forms.SendKeys]::SendWait("^{c}")</code>. 
  Will this target that certain window or just randomly send it to the current window?</p>
  
  <p>How can I change it to a certain window?</p>
  
  <p>This is my code:</p>
  
  <pre><code>Write-Host "Safe Botting V0.1"
  Write-Host "Initializing..."
  Start-Sleep -s 3
  Write-Host "Program started successfully with no errors."
  
  While($true)
  {
      Write-Host "Starting bot..."
      Start-Sleep -s 3
      Start-Process -FilePath E:\Documents\bot.exe
      Write-Host "Bot started successfully"
      $rnd = Get-Random -Minimum 1800 -Maximum 10800
      Write-Host "The bot will run for:"
      Write-Host $rnd
      Start-Sleep -s $rnd
      Write-Host "Bot will now stop!"
      [System.Windows.Forms.SendKeys]::SendWait("^{c}") 
      Write-Host "Bot terminated"
      Write-Host "Starting cooldown time"
      $rnb = Get-Random -Minimum 14400 -Maximum 28800
      Write-Host "The bot will cooldown for"
      Write-host $rnb
      Start-Sleep -s $rnb
      Write-Host "Cooldown Finished, Restarting"
      Start-Sleep -s 5
  }
  </code></pre>