How detect spacebar? [closed]

你说的曾经没有我的故事 提交于 2019-12-25 04:04:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!