❔ Stop a loop when a key is pressed
I'm making an app with a while loop that is supposed to repeat over and over until the user hits a key. I alredy have a Key instance with the key I need.
bool loop = true;
while (loop)
{
//Loop Stuff
if (IsKeyDown(myKey))
{
loop = false;
}
}
while (loop)
{
//Loop Stuff
if (IsKeyDown(myKey))
{
break;
}
}
But they didn't work.
Also, saw this in StackOverflow:
while(!Console.KeyAvailable)
{
//do work
} 
system.windows.input.keyboard.iskeydown?async void has no proper context and I get the feeling it straight up loses it, causing your cancellation token to not properly cancel.Keyboard.IsKeyDown(Key.A) ever reaches true, and see why it does not respond to it./close bool loop = true;
while (loop)
{
//Loop Stuff
if (IsKeyDown(myKey))
{
loop = false;
}
}
while (loop)
{
//Loop Stuff
if (IsKeyDown(myKey))
{
break;
}
}
But they didn't work.
Also, saw this in StackOverflow:
while(!Console.KeyAvailable)
{
//do work
} system.windows.input.keyboard.iskeydownasync voidKeyboard.IsKeyDown(Key.A)bool loop = true;
while (loop)
{
//Loop Stuff
if (Keyboard.IsKeyDown(Key.A))
{
loop = false;
}
}