M
Marc Scheuner [MVP ADSI]
Folks,
I have a command-line app that I'd like to show stuff onto the
Console. As a help to my users, I want to show the list of strings in
"pages", e.g. I'd like to pause output after x strings, and wait for
the user to either press "ENTER" to continue, or "ESC" to stop output.
Can't seem to get this to work in .NET ! .....
Here's my code fragment:
foreach(string sTemp in myArrayList)
{
ix++;
Console.WriteLine(ix.ToString("D3") + ": " + sTemp);
if(ix % 18 == 0)
{
Console.Write("---[ Any key to continue, Ctrl-C to
quit...]--- ");
int iKey = Console.Read();
if(iKey == -1)
{
Console.WriteLine();
return;
}
Console.WriteLine();
}
}
My first problem is that I can't seem to get just the next keypress
from the console - things like ESC and other keys are completely
swallowed, and never get detected.
With this solution, I can stop the output with a Ctrl-C - trouble is,
though - after the first 18 strings, the output jumps past the next 36
- it doesn't stop after string no. 36, but just goes on, and only
stops after string no. 54 again - from that point on, it also shows up
in two groups of 18 strings each.... don't quite understand why....
Any takers?? How can I trap keyboard input (I'd like to make it
possible that the user doesn't have to tap "ESC" and then "Enter" -
I'd like to be able to just detect "ESC" being pressed right away, and
abort. Or at least, I'd like to make this solution work so it'll
reliably always stop after my groups of 18 strings each.
Thanks!
Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
I have a command-line app that I'd like to show stuff onto the
Console. As a help to my users, I want to show the list of strings in
"pages", e.g. I'd like to pause output after x strings, and wait for
the user to either press "ENTER" to continue, or "ESC" to stop output.
Can't seem to get this to work in .NET ! .....
Here's my code fragment:
foreach(string sTemp in myArrayList)
{
ix++;
Console.WriteLine(ix.ToString("D3") + ": " + sTemp);
if(ix % 18 == 0)
{
Console.Write("---[ Any key to continue, Ctrl-C to
quit...]--- ");
int iKey = Console.Read();
if(iKey == -1)
{
Console.WriteLine();
return;
}
Console.WriteLine();
}
}
My first problem is that I can't seem to get just the next keypress
from the console - things like ESC and other keys are completely
swallowed, and never get detected.
With this solution, I can stop the output with a Ctrl-C - trouble is,
though - after the first 18 strings, the output jumps past the next 36
- it doesn't stop after string no. 36, but just goes on, and only
stops after string no. 54 again - from that point on, it also shows up
in two groups of 18 strings each.... don't quite understand why....
Any takers?? How can I trap keyboard input (I'd like to make it
possible that the user doesn't have to tap "ESC" and then "Enter" -
I'd like to be able to just detect "ESC" being pressed right away, and
abort. Or at least, I'd like to make this solution work so it'll
reliably always stop after my groups of 18 strings each.
Thanks!
Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch