该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#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++内容请搜索靠谱客的其他文章。
发表评论 取消回复