箭头键在终端仿真vai ssh中不起作用

时间:2014-04-24 06:59:44

标签: java bash ssh terminal terminal-emulator

在我自己的机器上进行ssh时,我可以在终端模拟器中使用Ctrl + P作为命令历史记录。我想知道是否可以使箭头键功能。我正在通过一个程序,而不是通过命令 ssh user @ host

为什么我这样问,是因为,在从字节数组中提取单个字符之前,我正在打印它。按下一个字符时,字节数组显示很多数字,但是当我按箭头键时,它什么都不打印。我必须使用箭头键才能按Ctrl + P工作。

请注意,SHELL值为/ bin / bash。另外,我已经尝试了TERM变量的这些值:dumb,vt100,xterm,linux。对于安全登录,我使用的是Ganymed SSH库。

更新:(来自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)
            {
            }

Key Listener代码是:

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();
            }
        };

感谢。

1 个答案:

答案 0 :(得分:0)

尝试使用 -t 键登录,例如ssh -t user@host

从手册页:

  

强制伪tty分配。这可以用来执行任意的   远程计算机上基于屏幕的程序,非常有用,   例如实施菜单服务时。

相关问题