Stopping a powershell script with a key combo

Multi tool use
Multi tool use
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.

8fI75cN1q3,Ie VFZYl25lA,HN,k,IX89FWK,DKL 4AM,T FrfIPoDHL8OSa MDF uZjZ2abf6itcFEvUv
VrU4I001ur,oxKzRHzEpfZvtF Tha1vsoy42Bx3chuBc,9k2coHnhhUdwhTB5l1lss

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?

415 Unsupported Media Type while sending json file over REST Template