在 ncurses 中捕获 control+key 的正确方法是什么?当前我在做它定义这样的控制:
#define ctl(x) ((x) & 0x1f)
Run Code Online (Sandbox Code Playgroud)
它工作正常,但问题是我无法同时捕捉 Cj 和 ENTER,这是因为:
j = 106 = 1101010
0x1f = 31 = 0011111
1101010 & 0011111 = 0001010 = 10 = ENTER key..
Run Code Online (Sandbox Code Playgroud)
那么..我该如何抓住它?谢谢!
-- 编辑:如果我尝试下面的代码,我无法正确捕捉回车键,即使在数字键盘中也是如此。Enter 被捕获为 ctrl-j。
#include <stdio.h>
#include <ncurses.h>
#define ctrl(x) ((x) & 0x1f)
int main(void) {
initscr();
int c = getch();
nonl();
switch (c) {
case KEY_ENTER:
printw("key: %c", c);
break;
case ctrl('j'):
printw("key: ctrl j");
break;
}
getch();
endwin();
return;
}
Run Code Online (Sandbox Code Playgroud)
新代码:
#include <stdio.h> …Run Code Online (Sandbox Code Playgroud) 我有这个程序:
\n\n#include <ncurses.h>\nint main () {\n initscr();\n mvaddstr(0, 0, " A B C D E ");\n mvaddstr(1, 24, "\xc3\xb1and\xc3\xb1");\n mvaddstr(1, 34, "esdr\xc3\xb1jul\xc3\xb1");\n refresh();\n getch();\n endwin();\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n当 ncurses 打印第一个单词 (\xc3\xb1and\xc3\xb1) 时,当随后移动到另一个位置(在本例中为 1, 34)时,实际上它会移动到另一个位置,因此第二个单词会打印在另一个位置柱子。
\n\n那么它应该是什么样子的:
\n\n A B C D E \n \xc3\xb1and\xc3\xb1 esdr\xc3\xb1jul\xc3\xb1\nRun Code Online (Sandbox Code Playgroud)\n\n看起来像这样:
\n\n A B C D E \n \xc3\xb1and\xc3\xb1 esdr\xc3\xb1jul\xc3\xb1\nRun Code Online (Sandbox Code Playgroud)\n\n因为第一个单词中有两个\'\xc3\xb1\'扩展ascii字符。
\n\n知道出了什么问题吗?\n谢谢!
\n