I need to check if spacebar or another key is pressed in a foreach (console application), something like this:
public static void WriteMessage(string text)
{
int speed = 150;
foreach (char c in text)
{
Console.Write(c);
if (Console.ReadKey().Key==ConsoleKey.Spacebar)
{
speed = 10;
}
else
{
speed = 150;
}
Thread.Sleep(speed);
}
}
but if i use Console.ReadKey()
in the if()
, the loop stops in this point, waiting a key pression
Sorry for bad english