如何检测空格键? [英] How detect spacebar?

查看:182
本文介绍了如何检测空格键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

使用 getchar 我需要按 intro

例如,我可以引入一个 intro code> intro ?

For example, can I introduce a intro without press intro???

推荐答案

简单示例

#include <iostream>

using namespace std;

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

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

编译代码

Windows.h:

Windows.h:

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

查看没有conio.h

See no conio.h

这篇关于如何检测空格键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆