我是靠谱客的博主 负责过客,这篇文章主要介绍linux程序接受键盘输入,C++ 如何捕获键盘的按键输入,现在分享给大家,希望可以做个参考。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

#include

#include

#include

#include

#include

#include

#include

void setBufferedInput(bool enable) {

static bool enabled = true;

static struct termios old;

struct termios new;

if (enable && !enabled) {

// restore the former settings

tcsetattr(STDIN_FILENO,TCSANOW,&old);

// set the new state

enabled = true;

} else if (!enable && enabled) {

// get the terminal settings for standard input

tcgetattr(STDIN_FILENO,&new);

// we want to keep the old setting to restore them at the end

old = new;

// disable canonical mode (buffered i/o) and local echo

new.c_lflag &=(~ICANON & ~ECHO);

// set the new settings immediately

tcsetattr(STDIN_FILENO,TCSANOW,&new);

// set the new state

enabled = false;

}

}

int main(int argc, char *argv[]) {

char c;

setBufferedInput(false);

while(true){

c=getchar();

switch(c){

case 68:

printf("%c",c);

break;

}

printf("%c",c);

}

return 0;

}

最后

以上就是负责过客最近收集整理的关于linux程序接受键盘输入,C++ 如何捕获键盘的按键输入的全部内容,更多相关linux程序接受键盘输入,C++内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(424)

评论列表共有 0 条评论

立即
投稿
返回
顶部