Click here to Skip to main content
15,919,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
f(){
info=console.readkey();
if(info == ConsoleKey.Escape)
console.write("exit");
int n = Convert.ToInt32(Console.ReadLine());
}


i need to say that if "escape" is pressed,quit.but
the first pressed character by user is not displayed in the window if its not escape...
Posted
Updated 19-Aug-11 7:54am
v7

C#
if(Console.ReadKey() == ConsoleKey.Escape)
 
Share this answer
 
v2
Comments
firstfox 19-Aug-11 13:47pm    
i have tried this..it works..my problem is that the if a user does not press the escape key first,the first character he presses is NOT displayed in the window..any ideas?
Simon Bang Terkildsen 19-Aug-11 14:08pm    
unless you pass true into Console.ReadKey then it is displayed in the console, if you're talking about Console.ReadLine not returning that character then that is current; You'll have to store the character yourselffor later usage
You might try below,

C#
static void ReadUserData()
{
    var info = Console.ReadKey();
    if (info.Key == ConsoleKey.Escape)
    {
        Console.WriteLine("exit");
    }
    else
    {
        Console.WriteLine(string.Format("\nKey has been pressed : {0}", info.Key));
        int n;
        n = Int32.TryParse(Console.ReadLine(), out n) ? n : 0;
        Console.WriteLine(n);
    }
}


:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900