2013-04-25 100 views
0

運行下面的代碼來確定正確的關鍵碼Ctrl鍵 + 向下使用詛咒給我兩個不同的輸出(兩個服務器正在運行Debian 6)。不同鍵碼行爲和詛咒

ssh server1(錯誤輸出):

Press a Key 27 
Press a Key 91 
Press a Key 66 

ssh server2(正確的輸出):

Press a Key 519 

我失去了在代碼中還是在終端的東西嗎?可能是什麼問題呢?

#include <stdlib.h> 
#include <ctype.h> 
#include <curses.h> 

int main(void) 
{ 
WINDOW *_window = initscr(); 
int _rows; 
int _cols; 

cbreak(); 

/* Accept all keys */ 
keypad(_window, true); 

/* Don't echo things that are typed */ 
noecho(); 

/* Get the screen dimensions */ 
getmaxyx(_window, _rows, _cols); 

/* Don't display cursor */ 
curs_set(0); 

for (;;) 
{ 
    printw("Press a Key "); 
    refresh(); 
    int key = wgetch(_window); 
    printw("%d \n", key); 
} 

endwin(); 

return 0; 
} 
+0

什麼是在服務器上設置的TERM環境變量? – parkydr 2013-04-25 11:47:57

+0

'server1':screen-256color,'server2':'xterm'。顯然這與tmux有關。分離tmux會話很好。但是,仍然會很高興知道是否有可以在代碼中實施的解決方法。 – user1024718 2013-04-25 12:49:27

+0

我不這麼認爲,關鍵映射是由TERM變量決定的。你可以嘗試在server1上設置TERM = xterm。 – parkydr 2013-04-25 13:21:48

回答

0

它不工作,因爲你正在使用的screen命令和TERM變量設置爲屏幕256color。

我以爲screen -a,它使用更多的術語,可能工作,但它不。

我發現的唯一方法是將TERM設置爲xterm,以便您可以在xterm或程序中對此進行設置。

setenv("TERM","xterm",1); 

這不是一個理想的解決方案,它只會用xterm這樣的終端工作,但它是爲您的特定問題的方法。