Stopping a powershell script with a key combo

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Stopping a powershell script with a key combo



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.


$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"

}
}









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS