How do i supress keypress being printed to console in .NET?

Posted by cbsch on Stack Overflow See other posts from Stack Overflow or by cbsch
Published on 2010-03-20T18:52:05Z Indexed on 2010/03/20 19:01 UTC
Read the original article Hit count: 333

Filed under:
|
|

Hello, I'm porting a small C++ console game to C# and it seems that I can't stop key presses from being printed to the console.

In C++ I get the keystroke with this method, which also suppress the keystrokes from being printed to the console:

bool Game::getInput(char *c)
{
    if (_kbhit())
    {
        *c = _getch();
        return true;
    }
    return false;
}

I tried to do the equivalent in C# by doing:

Key = Console.ReadKey();

But this does not suppress the character from being printed to the console, causing obvious problems. Any ideas on how to remedy this?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET