问题
I have a program in c++ where I have to detect spacebar, how can I do? I see that I need the function getch()
, but in my program I haven´t conio.h
. Exist other solution?
With getchar
I need press intro
, exist other form that I press only spacebar?
For example, can I introduce a intro
without press intro
???
回答1:
Simple Example
#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);
See no conio.h
来源:https://stackoverflow.com/questions/27937617/how-detect-spacebar