ASCII Codes for Up, Down, Left, and Right Arrows

I am writing a program that reads input from Javascript and sends these readings to bash.

I can successfully launch many actions, such as the letters "AZ", TAB, CTRL + C, etc. But I understand that I can not send bash to the ARROW correctly.

If I read ascii code from Javascript, I get the following as described Arrow keys in JS / jQuery

37 - left
38 - up
39 - right
40 - down

However, when I send the arrow to the terminal, decimal key code 38, I write ampersand (as, following the ascii table http://www.asciitable.com/ )

So my question is: what code do I need to send from Java to bash in order to tell bash the up arrow?

PD_ I understand that it may differ depending on the operating system, and this code cannot be considered the ascii code, as this message suggests: enter a description of the link here

Edit I am writing from Java to bash with the following code:

JSch jsch = new JSch();
[...]
Channel channel = session.openChannel("shell");
OutputStream out = channel.getOutputStream();
out.write(asciiDecimalCode); // send characters

Thanks in advance.

+4
source share
1 answer

Escape sequence for up arrow "\u001b[A". \u001bis the code for ESC (Escape) .

This means that while you have one key code in JavaScript, you need to write 3 bytes in BASH to achieve the desired effect.

You can see it for yourself by typing Ctrl+V Up.

Ctrl+V bash: " , ".

:

+7

Source: https://habr.com/ru/post/1539890/


All Articles