GNU readline和键绑定

时间:2011-08-31 13:38:35

标签: gnu readline key-bindings

我从GNU getline文档中读到,它能够将一些回调函数绑定到某些键。我已经知道如何使用rl_bind_key函数将动作绑定到 TAB 键。

但是如何使用它将某些动作绑定到以下键?: CTRL + TAB ESC PAUSE / BREAK

1 个答案:

答案 0 :(得分:3)

#include <stdio.h>

#include <readline/readline.h>

int my_cool_readline_func (int count, int key) {
   printf ("key pressed: %d\n", key);
   rl_on_new_line ();
   return 0;
}

int main(void) {
     rl_command_func_t my_cool_readline_func;
     rl_bind_key ('\t', my_cool_readline_func);
     rl_bind_key (27, my_cool_readline_func); /* ascii code for ESC */
     rl_bind_keyseq ("\\C-a", my_cool_readline_func);

     while (1) {
         char *line = readline ("rl> ");
     }
}

如果您正在运行GNU系统(或其中一个变体),请运行:

info readline "command line editing" "introduction" # notation convention
info readline "programming" "readline" "biding" # biding functions