用curses.h调用函数

时间:2012-11-18 05:59:01

标签: ncurses

这是我第一次使用curses.h。我在上面发布了我的代码。当按下向右或向左箭头时,我需要进行一些函数调用。当我向我的代码添加绘图函数调用时,它在按下箭头键时不会绘制,但是在用户按下'q'后程序终止时绘制。有任何想法吗?

int main(int argc, char * argv[] )
    {
      setup_curses();  
      c = getch();


      while(1)
      {   
        if (c != ERR)
        {
          move(5,0);
          printw("left arrow key rotates counter-clockwise, right clockwise, space for thrust, q to quit.");
          if (c == KEY_LEFT)
            draw();
          else if (c == KEY_RIGHT) 
            draw();
          else if (c == ' ')
            printw("do something");
          else if (c == 'q')
            break;
          refresh();

        }

        c = getch();

      }



    unset_curses();
    exit(EXIT_SUCCESS);
    }


        void setup_curses()
        {
          initscr();
          cbreak();
          noecho();
          keypad(stdscr, true);
        }

        void unset_curses()
        {
          keypad(stdscr, false);
          nodelay(stdscr, false);
          nocbreak();
          echo();
          endwin();
        }

0 个答案:

没有答案