我正在写一个函数,获取用户输入并根据用户输入的内容执行操作。我正在使用一个case语句来检查用户输入的内容。C++键输入检查
我很难看到用户是否按住home,end,ins和del。默认变量如HOME,INSERT,DELETE和END似乎没有效果,但箭头键使用LEFT和RIGHT。我在GNU/Linux中这样做。我不确定我做错了什么。
任何帮助将不胜感激。
我正在写一个函数,获取用户输入并根据用户输入的内容执行操作。我正在使用一个case语句来检查用户输入的内容。C++键输入检查
我很难看到用户是否按住home,end,ins和del。默认变量如HOME,INSERT,DELETE和END似乎没有效果,但箭头键使用LEFT和RIGHT。我在GNU/Linux中这样做。我不确定我做错了什么。
任何帮助将不胜感激。
这里是问题:
#include <stdio.h>
//Compiled on GNU/Linux
//By: Saulius Grybas
int main()
{
int key;
bool done = false;
while (!done)
{
key = getchar();
switch (key){
case HOME:
//Home key is pressed/perform action
done = true;
break;
case END:
//END key is pressed/perform action
done = true;
break;
case DEL:
//DEL key is presed/perform action
done = true;
break;
case BACKSPACE:
//backspace is pressed/perform action
done = true;
break;
default:
done = false;
break;
}
printf ("%d%s\n", key, " - Integer of key is pressed!");
}
return 0;
}
这些定义用于按键的扫描代码(IBM PC)。所有数字都是十进制的。
#define PAGE_UP 73
#define HOME 71
#define END 79
#define PAGE_DOWN 81
#define UP_ARROW 72
#define LEFT_ARROW 75
#define DOWN_ARROW 80
#define RIGHT_ARROW 77
#define F1 59
#define F2 60
#define F3 61
#define F4 62
#define F5 63
#define F6 64
#define F7 65
#define F8 66
#define F9 67
#define F10 68
#include <iostream>
#include <conio.h>
这里有Linux的扫描码:http://www.comptechdoc.org/os/linux/howlinuxworks/linux_hlkeycodes.html
如果你表现出你有这将是人们更容易地帮助你,你怎么刚从的getchar例如读取 – lijat
用户输入的代码()函数 –