如何检测空格键?

How detect spacebar?

我有一个 C++ 程序,我必须在其中检测空格键,我该怎么做?我看到我需要函数 getch(),但在我的程序中我没有 conio.h。是否存在其他解决方案?

使用 getchar 我需要按 intro,是否存在我只按空格键的其他形式?

比如我可以不按intro引入一个intro吗???

简单示例

#include <iostream>

using namespace std;

int main()
{
    char ans;
    do
    {
        //code
    }
    while(getchar() != 32 || getchar() != ' ');

   cout << "Space pressed" << endl;
   return 0;
}

Compiled Code

Windows.h:

if(GetAsyncKeyState(VK_SPACE) & 0x80000000)
     MessageBox(NULL, "Spacebar pressed!", "TEST", MB_OK);

没看到conio.h