2014-04-24 24 views
0

工作,而在我自己的機器ssh'ing,我能夠在終端仿真器使用Ctrl + P的命令歷史記錄。我想知道是否有可能使箭頭鍵功能。我通過程序ssh'ing,而不是通過命令SSH用戶@主機待辦事項箭頭鍵並不在終端仿真奧鋼聯的ssh

爲什麼我問這個,是因爲從字節數組中提取單個字符之前,我打印出來。當按下一個字符時,字節數組顯示很多數字,但是當我按下箭頭鍵時,它不打印任何東西。我必須編制箭頭鍵才能起到Ctrl + P的作用。

請注意,SHELL值/斌/慶典。另外,我嘗試了TERM變量的這些值:dumb,vt100,xterm,linux。爲了安全登錄,我使用了Ganymed SSH庫。

UPDATE:(與來自tripleee建議)

鍵盤的處理邏輯的一個小片段如下:

for (int i = 0; i < len; i++) 
      { 

       char c = (char) (data[i] & 0xff); 
       System.out.print(c + ", "); 
       if (c == 8) 
       { 
        if (posx < 0) 
         continue; 
        posx--; 
        continue; 
       } 

       if (c == '\r') 
       { 
        posx = 0; 
        continue; 
       } 

       if (c == '\n') 
       { 
        posy++; 
        if (posy >= y) 
        { 
         for (int k = 1; k < y; k++) 
          lines[k - 1] = lines[k]; 
         posy--; 
         lines[y - 1] = new char[x]; 
         for (int k = 0; k < x; k++) 
          lines[y - 1][k] = ' '; 
        } 

        continue; 
       } 
}//some more stuff and then the appending of characters with the previous ones 

輸入進來這種方式:

byte[] buff = new byte[8192]; 

      try 
      { 
       while (true) 
       { 
        int len = in.read(buff); 
        if (len == -1) 
         return; 
        addText(buff, len); 
       } 
      } 
      catch (Exception e) 
      { 
      } 

關鍵監聽器代碼:

KeyAdapter kl = new KeyAdapter() 
     { 
      public void keyTyped(KeyEvent e) 
      { 
       System.out.println("EVENT IS: " + e.getKeyCode()); 
       int c = e.getKeyChar(); 

       try 
       { 
        out.write(c); 
       } 
       catch (IOException e1) 
       { 
       } 
       e.consume(); 
      } 
     }; 

謝謝。

使用 -t
+0

如果遠程應用程序做自己的鍵盤處理,它可能無法使其接受箭頭鍵無需更改代碼。 – tripleee

+0

@tripleee:是的,在程序中,一次提取一個字符,並且有一些條件會根據其ASCII值處理該字符。我正在嘗試使用箭頭鍵ASCII值做同樣的事情,但它似乎不會在終端中觸發。 – E1T1

+0

箭頭鍵不是「ASCII」。根據終端仿真的不同,它們通常是作爲某種逃生或控制代碼傳輸的。舉例來說,在我的膩子窗口(我想VT220仿真?),向上的箭頭髮射Esc鍵[A. – tripleee

回答

0

嘗試登錄,例如ssh -t [email protected]

從手冊頁:

部隊僞終端分配。這可用於在遠程機器上執行任意 基於屏幕的程序,這可能非常有用,例如 當實現菜單服務時。