2012-02-09 170 views
0

嘿,我已經測試了getch和getchar,但它的輸入wating,我認爲必須有讀取鍵盤緩衝區funktion。 部分我的代碼Ncurses鍵盤輸入

while (1) { 
    if (key!='r') 
    { 
     if (key!='q') 
     { 
      mvprintw(LINES-2, 1, "Display will refresh in %2d seconds ", t); 
      refresh(); 
      sleep(1); 
      t--; 
      break; 
     } 
     else 
     { 
     exit (0); 
     } 
    } 
    else 
    { 
    return; 
    } 

}

+0

您是否試過'read(1,buffer,buffer_size)'? – Eregrith 2012-02-09 09:36:46

回答

4

如果你不想做getch()等待,你必須將它設置爲非阻塞,與nodelay()

執行後:

if (nodelay (pWin, 1) == ERR) { 
    // some error occurred. 
} 

然後getch()將返回ERR如果沒有輸入可用。

輸入選項的聯機幫助頁是here,並且在其自身的聯機幫助頁中提及了getch的行爲,鏈接here


的NODELAY選項導致的getch成爲一個無阻塞呼叫。如果沒有輸入就緒,getch返回ERR。如果禁用(bf爲FALSE),getch會一直等到按下某個鍵。


在無延遲模式中,如果沒有輸入等待,則返回值ERR。

+0

嘿我已經用nodelay(stdscr,TRUE)解決了它;和 小鍵盤(stdscr,TRUE); NOECHO(); – Mar 2012-02-09 10:03:56