【问题标题】:C++ change canonical mode in windowsC ++在Windows中更改规范模式
【发布时间】:2014-06-17 11:11:45
【问题描述】:

在这上面找到一堆线程后,我在 Windows 上没有找到任何线程,只有 Linux、Ubuntu 等。

简而言之,我想知道的是如何关闭规范模式,以便控制台中的输入导致即时输入,而无需按 Enter。

更长的版本。这就是我现在正在尝试做的事情: 当 PGM 暂停(基于文本的游戏)时,要求用户输入箭头键以在 2D 阵列上移动玩家。但是cin.get()cin.ignore() 和我尝试过的其他一些事情都需要按回车才能继续。

臭名昭著的system("pause>nul"); 确实确实有效,但正如我在其他地方看到的那样,这是非常糟糕的做法。

这是代码的一部分。 cout 语句仅用于测试目的:

//While loop
if(GetAsyncKeyState(VK_UP)){
        cout << "up" << endl;
}
else if(GetAsyncKeyState(VK_DOWN)){
        cout << "down" << endl;
}
else if(GetAsyncKeyState(VK_LEFT)){
        cout << "left" << endl;
}
else if(GetAsyncKeyState(VK_RIGHT)){
        cout << "right" << endl;
}
else{
    break;}

//pauze and check for arrow key input here

【问题讨论】:

    标签: c++ include


    【解决方案1】:

    您也可以在 Windows 上使用getch

    我知道它是 C,并且您收到了已弃用的警告,但它可以工作......

    此代码循环运行,直到您按下 Enter:

    检查按下箭头键时会发生什么...

    #include <stdio.h>
    #include<conio.h>
    int main ()
    {
      int c;
      do {
        c=getch();
        printf("%d\n",c);
      } while (c != 13);
      return 0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-18
      • 1970-01-01
      • 2016-05-04
      • 1970-01-01
      • 2013-08-13
      • 2016-12-14
      • 2010-11-29
      相关资源
      最近更新 更多