微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 ncurses 获取所有当前可用的输入?

如何解决如何使用 ncurses 获取所有当前可用的输入?

让我们考虑这个例子:

#include <ncurses.h>
#include <unistd.h>


// ...
// Some functions like `contains` and `getBuff`
// ...

int main() {
  initscr();                        // Init curses mode
  // ... Do some initialisation

  int *input;                       // Input buffer

  while(1) {
    getBuff(input);                 // Get all characters currently available into buffer
    if(contains(input,'q')) break; // If there is 'q' in buffer - break
    // ... Do something with buffer
    usleep(100000);                 // Wait some time
  }

  endwin();                         // Exit curses
  return 0;
}

在这里,程序在循环中等待一段时间,然后在它休眠时获得所有输入。
主要问题在于 getBuff() — 我不知道如何制作。

我曾尝试使用 halfdelay()while(getch() != ERR),但效果不佳。如果用户按下任意键且不松开,则程序停止循环。

因此,getBuff() 可能会调用获取所有输入,而不是稍后。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。