代码之家  ›  专栏  ›  技术社区  ›  Edward Z. Yang

转换为外部外壳和背面的键

  •  5
  • Edward Z. Yang  · 技术社区  · 15 年前

    我有一个ncurses应用程序,它正在为 临时退出ncurses,运行外部 编辑器/shell/无论什么,然后在完成后返回到ncurses。

    这个~几乎可以用,除了前几个不舒服的按键 事后得到的显然是伪造的;努尔斯认为 如果我按两次向上箭头。

    以前见过这种行为的人都知道该怎么解决 这是?如果有帮助的话,这是RubyNcurses库。

    2 回复  |  直到 15 年前
        1
  •  1
  •   Edward Z. Yang    15 年前

    在翻了一番之后,我找到了一个货物崇拜的解决方案:在stdscr上取出外壳后,显式地调用键盘(1)。我不知道为什么会这样,但确实如此。如果他们能解释原因,我会把别人的回答标记为是。 当前的工作原理是键盘接触到某种内部缓冲区并清除它。

    划伤:

    NCURSES_EXPORT(int)
    keypad(WINDOW *win, bool flag)
    {
        T((T_CALLED("keypad(%p,%d)"), win, flag));
    
        if (win) {
            win->_use_keypad = flag;
            returnCode(_nc_keypad(SP, flag));
        } else
            returnCode(ERR);
    }
        2
  •  0
  •   Gabe    15 年前

    是啊。如果没有键盘,NCURES将无法为您处理转义码。从键盘手册页:

       The keypad option enables the keypad of the user's  terminal.   If  en-
       abled (bf is TRUE), the user can press a function key (such as an arrow
       key) and wgetch returns a single value representing the  function  key,
       as in KEY_LEFT.  If disabled (bf is FALSE), curses does not treat func-
       tion keys specially and the program has to  interpret  the  escape  se-
       quences  itself.   If the keypad in the terminal can be turned on (made
       to transmit) and off (made to work locally),  turning  on  this  option
       causes  the terminal keypad to be turned on when wgetch is called.  The
       default value for keypad is false.
    

    通常,我在ncurses程序中做的第一件事是调用小键盘(stdscr,true),以启用良好的键盘映射。

    希望有帮助。