On Fri, 29 Dec 2006 15:29:24 -0400, "Marco Shaw"
<marcoDOTshaw_@_gmailDOTcomwrote:
>C# novice...
Can I create a console application (think the Pine email reader or even
'edit' in DOS) where I can use my up/down/side arrows to move around the
app?
Yes.
>Any hints/pointers to get me started?
Marco
Use elements of Console for the cursor moving bit: CursorTop,
CursorLeft, KeyInfo, ConsoleKey, KeyAvailable and Read(). You may
also need System.Threading.Thread.Sleep() to wait for a key to be
pressed.
I don't know how much of a hint you want, but don't read any further
if you don't want to see a very simple demonstration.
rossum
static void Main() {
string twentyDots = new string('.', 20);
for (int i = 0; i < 10; ++i) {
Console.WriteLine(twentyDots);
} // end for
Console.WriteLine("Use arrow keys to move or X to exit.");
// Initial position of cursor
Console.CursorLeft = 9;
Console.CursorTop = 4;
// Loop to read keyboard
bool finished = false;
ConsoleKeyInfo keyInfo = new ConsoleKeyInfo();
do {
// Wait until key is pressed.
while (Console.KeyAvailable == false) {
Thread.Sleep(100);
} // end while
// 'true' stops key echo.
keyInfo = Console.ReadKey(true);
switch (keyInfo.Key) {
case ConsoleKey.DownArrow:
++Console.CursorTop;
break;
case ConsoleKey.LeftArrow:
--Console.CursorLeft;
break;
case ConsoleKey.RightArrow:
++Console.CursorLeft;
break;
case ConsoleKey.UpArrow:
--Console.CursorTop;
break;
case ConsoleKey.X:
finished = true;
break;
default:
break;
} // end switch
} while (!finished);
} // end Main()