如何阻止c++ NCurses显示按下的键
How to block C++ NCurses from showing pressed key?
我目前正在用c++创建一个井字游戏。在放置贴图的函数中,我使用了一个无止境的while循环来检查getch(),然后移动光标或放置贴图。然而,当我按下其他东西,然后输入或箭头,它写在板上的字符。但我不想那样。你能告诉我怎么做吗?
bool moveCursor ( void )
{
int c;
int tmpX = m_Xpos;
int tmpY = m_Ypos;
while (1){
c = getch();
if(c == KEY_LEFT) tmpX--;
if(c == KEY_RIGHT) tmpX++;
if(c == KEY_UP) tmpY--;
if(c == KEY_DOWN) tmpY++;
if (tmpY > m_len ) tmpY--;
if (tmpX > m_len ) tmpX--;
if (tmpY < 1 ) tmpY++;
if (tmpX < 1 ) tmpX++;
if(c == 'q') return false;
if(c == 'n')
{
m_Ypos = tmpY;
m_Xpos = tmpX;
if (checkValidMove(tmpY,tmpX))
{
break;
}
}
if ( c != KEY_LEFT && c != KEY_RIGHT && c != KEY_UP && c != KEY_DOWN && c != 'q' && c != 'n' ) continue;//my try to fix it, but didn't work
move(tmpY,tmpX);
refresh();
}
return true;
}
所以,是的,我有点愚蠢-我只是不得不使用noecho()选项
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 是什么阻止DOMTimerCoordinator::NextID进入无休止的循环
- 程序崩溃并显示"std::out_of_range"错误
- C++控制台应用程序阻止退出
- Python中的for循环与C++有何不同
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 显示阻止消息框
- 如果显示错误,如何阻止代码运行
- 使用复杂的显示函数会阻止glutKeyboardFunc工作
- 如何阻止空格在从文件中读取时显示为回车符?
- 如何在打开外部应用程序时阻止控制台显示
- 我怎么能阻止我的整数显示为十六进制
- 代码::阻止控制台应用不显示输出
- 如何阻止QApplication显示在dock中?
- 如何阻止c++ NCurses显示按下的键