Any Key

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need a console based application to pause until the user is ready to
proceed. I would prefer to do some thing like
console.writeline("Press any key to continue . . . . ")
//some how make it wait for any char to be pressed ie getch() in C

thanks
 
Use the Console.Read() function. Here is a MS example:

int i;
char c;
while (true)
{
i = Console.Read ();
if (i == -1) break;
c = (char) i;
Console.WriteLine ("Echo: {0}", c);
}
Console.WriteLine ("Done");
return 0;
 
Thank You sir Much aprreciated

ValyaS said:
Use the Console.Read() function. Here is a MS example:

int i;
char c;
while (true)
{
i = Console.Read ();
if (i == -1) break;
c = (char) i;
Console.WriteLine ("Echo: {0}", c);
}
Console.WriteLine ("Done");
return 0;
 
Doesnot work user still has to press enter for progression i want any char to
cause the code to proceed
 
Shamefoot said:
Doesnot work user still has to press enter for progression i want any char to
cause the code to proceed
:

This is currently not possible in .Net. You can't just read one key
without enter, I've seen an article using P/Invoke to get around it, but
can't find the url back.

Yves
 
This is currently not possible in .Net. You can't just read one key
without enter, I've seen an article using P/Invoke to get around it, but
can't find the url back.

Yves

Fortunately, in Whidbey (VS 2005), you will be able to do that again.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Yes got the beta version and it works well enough :)


ConsoleKeyInfo keyPressed = new ConsoleKeyInfo();

Console.Writeline("Please Press a key to continue . . . . ");
while ( ! Console.KeyAvailable )
{
Thread.Sleep(100);
}
keyPressed = Console.ReadKey( true );
Console.WriteLine( "You pressed {0}", keyPressed.Key );
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top