GNU 编译器 KEY_F 未检测到功能键
基本上,我对控制台应用程序进行了按键检测,但由于某种原因它没有检测功能键。
这是我的代码,我在 Linux 上使用 GNU 编译器。任何帮助或想法将不胜感激。
refresh();
key = getch();
switch(key) {
case KEY_HOME: key = HOME; break;
case KEY_END: key = END; break;
case KEY_UP: key = UP; break;
case KEY_DOWN: key = DOWN; break;
case KEY_LEFT: key = LEFT; break;
case KEY_RIGHT: key = RIGHT; break;
case KEY_NPAGE: key = PGDN; break;
case KEY_PPAGE: key = PGUP; break;
case KEY_DC: key = DEL; break;
case KEY_IC: key = INSERT; break;
case KEY_F(1): key = F(1); break;
case KEY_F(2): key = F(2); break;
case KEY_F(3): key = F(3); break;
case KEY_F(4): key = F(4); break;
case KEY_F(5): key = F(5); break;
case KEY_F(6): key = F(6); break;
case KEY_F(7): key = F(7); break;
case KEY_F(8): key = F(8); break;
case KEY_F(9): key = F(9); break;
case KEY_F(10): key = F(10); break;
case KEY_F(11): key = F(11); break;
case KEY_F(12): key = F(12); break;
case KEY_ENTER: key = ENTER; break;
case KEY_BACKSPACE: key = BACKSPACE; break;
default:
//key = F(2); //For any function keypress, it jumps to default
if (NON_ASCII(key) != 0)
key = UNKNOWN;
}
Basically, I have key detection for my console application, for some reason it's not detecting function keys.
Here is my code, I'm using GNU compiler on linux. Any help or ideas would be greatly appreciated.
refresh();
key = getch();
switch(key) {
case KEY_HOME: key = HOME; break;
case KEY_END: key = END; break;
case KEY_UP: key = UP; break;
case KEY_DOWN: key = DOWN; break;
case KEY_LEFT: key = LEFT; break;
case KEY_RIGHT: key = RIGHT; break;
case KEY_NPAGE: key = PGDN; break;
case KEY_PPAGE: key = PGUP; break;
case KEY_DC: key = DEL; break;
case KEY_IC: key = INSERT; break;
case KEY_F(1): key = F(1); break;
case KEY_F(2): key = F(2); break;
case KEY_F(3): key = F(3); break;
case KEY_F(4): key = F(4); break;
case KEY_F(5): key = F(5); break;
case KEY_F(6): key = F(6); break;
case KEY_F(7): key = F(7); break;
case KEY_F(8): key = F(8); break;
case KEY_F(9): key = F(9); break;
case KEY_F(10): key = F(10); break;
case KEY_F(11): key = F(11); break;
case KEY_F(12): key = F(12); break;
case KEY_ENTER: key = ENTER; break;
case KEY_BACKSPACE: key = BACKSPACE; break;
default:
//key = F(2); //For any function keypress, it jumps to default
if (NON_ASCII(key) != 0)
key = UNKNOWN;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不是诅咒专家,但是阅读了一些手册页后我发现了这个程序:
当我按 F 键时,我得到一个 3 字符序列:27, 79, (80 + N-1),其中 N 是F 键的编号。我认为你的交换机必须识别出该键是转义序列并对其进行特殊处理。
编辑:该模式仅适用于 F1-F4。 F5 改变它。您可能想要合并来自curses 的F(n) 宏。
I'm not a curses expert, but a bit of reading man pages netted me this program:
When I press an F key, I get a 3-character sequence: 27, 79, (80 + N-1) where N is the number of the F key. I think your switch will have to recognize that the key is an escape sequence and handle it specially.
Edit: That pattern holds only for F1-F4. F5 changes it up. You'll probably want to incorporate the F(n) macros from curses.
个人也有同样的问题。
将 F(n) 宏转换为 char 类型神奇地为我解决了这个问题;
等等。曾为 F2 至 F10 加 F12 工作。 F 的 1、10 和 11 被“占用”,因为我的 xterm 上没有更好的词。 (F1 打开帮助窗口,F11 切换全屏模式等)再次强调,我无法开始猜测为什么会这样。
Having the same issue, personally.
Casting the F(n) macro to a char type magically cleared the issue for me;
and the like. Worked for F2 through F10 plus F12. F's 1, 10 and 11 are "occupied" for lack of a better word on my xterm. (F1 opens the help window, F11 toggles fullscreen mode, etc.) Again, I can't emphasize enough that I couldn't begin to guess why that works.
您可能需要使用
keypad
功能启用终端的“键盘”功能。从键盘(3x) 手册页:You may need to enable the "keypad" functionality of the terminal using the
keypad
function. From the keypad(3x) manual page: