title: Stopping a powershell script with a key combo
body: <p>I have been trying to stop a loop in powershell using multiple keys. I wanted something that wouldn't be normally or accidentally pressed, like Fn-F8, or any two key combination. I do not want to use ctrl-c, as the program will run in the background and it will have to do some "cleaning up" upon ending. The code I have below will end by pressing a single key, but that is as much as I could figure out. 
  Thanks in advance.</p>
  
  <pre><code>$continue = $true
  while($continue)
  {
      if ([console]::KeyAvailable)
      {
          echo "Toggle with F12";
          $x = [System.Console]::ReadKey() 
  
          switch ( $x.key)
          {
              F8 { $continue = $false }   
          }
      } 
      else
      {
          # Prints a loop is ended
          Write-Output "1"
      }    
  }
  </code></pre>