我正在寫一個函數,獲取用戶輸入並根據用戶輸入的內容執行操作。我正在使用一個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
用戶輸入的代碼()函數 –