<分区>
我有一个 C++ 程序,我必须在其中检测空格键,我该怎么做?我看到我需要函数 getch()
,但在我的程序中我没有 conio.h
。是否存在其他解决方案?
使用 getchar
我需要按 intro
,是否存在我只按空格键的其他形式?
例如,我可以在不按 intro
的情况下介绍一个 intro
吗???
标签 c++ codeblocks
<分区>
我有一个 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;
}
Windows.h:
if(GetAsyncKeyState(VK_SPACE) & 0x80000000)
MessageBox(NULL, "Spacebar pressed!", "TEST", MB_OK);
看不到conio.h
关于c++ - 如何检测空格键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27937617/