0

While ssh'ing in my own machine, I am able to use Ctrl+P for command history in the terminal emulator. I wanted to know is it possible to make arrow keys function as well. I am ssh'ing through a program, not through the command ssh user@host

Why I am asking this, is because, before extracting individual characters from the byte array, I am printing it. When a character is pressed, the byte array shows a lot of numbers, but when I press an arrow key, it prints nothing. I have to make up arrow key to function as Ctrl+P works.

Please note that the SHELL value is /bin/bash. Also, I have experimented with these values of TERM variable : dumb, vt100, xterm, linux .For secure login, I am using Ganymed SSH library.

UPDATE: (with suggestions from tripleee)

A little snippet of keyboard processing logic is as follows:

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

The input comes in this way:

byte[] buff = new byte[8192];

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

The Key Listener code is :

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

Thanks.

4

1 回答 1

0

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

从手册页:

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

于 2014-04-26T15:05:41.770 回答