Non-blocking getch(), ncurses

后端 未结 3 624
轻奢々
轻奢々 2020-12-03 01:06

I\'m having some problems getting ncurses\' getch() to block. Default operation seems to be non-blocking (or have I missed some initialization)? I would like it to work like

3条回答
  •  鱼传尺愫
    2020-12-03 01:55

    You need to call initscr() or newterm() to initialize curses before it will work. This works fine for me:

    #include 
    
    int main() {
        WINDOW *w;
        char c;
    
        w = initscr();
        timeout(3000);
        c = getch();
        endwin();
    
        printf("received %c (%d)\n", c, (int) c);
    }
    

提交回复
热议问题