Recognising ESC key in console application

  • Thread starter Thread starter simonc
  • Start date Start date
S

simonc

If I have a point in a console application where I want the user to respond to

Press ENTER to continue or ESCAPE to exit

how can I get the application to recognise the escape key?

Grateful for advice
 
simonc said:
If I have a point in a console application where I want the user to respond to

Press ENTER to continue or ESCAPE to exit

how can I get the application to recognise the escape key?

Grateful for advice

Use Console.ReadKey() which returns a ConsoleKeyInfo object. Use the
returned object.Key to compare to ConsoleKey.Escape and ConsoleKey.Enter
to direct your code.
 
Thanks for this suggestion. The problem is that I am using Visual Basic.NET
2002 and console.readkey seems to be a more recent addition. Do you know if
there is an equivalent method that will work on older versions?

Many thanks
 
simonc said:
Thanks for this suggestion. The problem is that I am using Visual Basic.NET
2002 and console.readkey seems to be a more recent addition. Do you know if
there is an equivalent method that will work on older versions?

Many thanks

My first thought would be to upgrade to vb 2008 express, which is free. If
that is not an option, then look at
http://www.pinvoke.net/default.aspx/msvcrt/kbhit.html. This seems to point
to the windows api function that ReadKey is using behind the scenes.

Mike
 
My first thought would be to upgrade to vb 2008 express, which is free.

Marvellous, isn't it! VB6 is currently worth its weight in gold whilst VB
2008 is having trouble giving itself away!

Mike
 
Back
Top