我如何在打印苏preSS键preSS在

我如何在打印苏preSS键preSS在

本文介绍了我如何在打印苏preSS键preSS在.NET安慰?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我移植一个小的C ++单机游戏到C#,似乎我不能被打印到控制台停止键presses。

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.

在C ++中,我得到的按键用这种方法,这也SUP preSS的按键被打印到控制台:

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;
}

我试图做这样做相当于在C#:

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

Key = Console.ReadKey();

但这并不燮preSS被打印到控制台,造成明显的问题人物。关于如何解决这个任何想法?

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

推荐答案

您想<$c$c>Console.ReadKey(true)

获取由用户pssed的下一个字符或功能键$ P $。在pressed键选择是否显示在控制台窗口。

参数 - 这就是所谓的拦截的:

The argument - which is called intercept:

确定是否显示在控制台窗口中的pressed关键。 真正以不显示pssed键$ P $;否则,

这篇关于我如何在打印苏preSS键preSS在.NET安慰?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 14:11