Recognising ESC key in console application

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
 
F

Family Tree Mike

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.
 
S

simonc

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
 
F

Family Tree Mike

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
 
M

Mike Williams

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
 

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

Top