如何阻止c++ NCurses显示按下的键

How to block C++ NCurses from showing pressed key?

本文关键字:显示 何阻止 c++ NCurses      更新时间:2023-10-16

我目前正在用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()选项