I am writing a program that reads input from Javascript and send those readings to bash.
I can successfully run many actions, like "A-Z" letters, TAB, CTRL+C, etc. But I realize that I cannot send properly to bash the ARROW UP.
If I read the ascii code from Javascript, I get the following as explained Binding arrow keys in JS/jQuery
37 - left
38 - up
39 - right
40 - down
However, when I send arrow up to the terminal, decimal key code 38, I write an ampersand (as by following a ascii table http://www.asciitable.com/)
So, my question is: what code do I have to send from Java to bash to tell bash "arrow key up" ?
PD_ I realize that it might be different depending on the operating system and this code might not be considered an ascii code as this post suggest: enter link description here
Edit I write from Java to bash by using the following code:
JSch jsch = new JSch();
[...]
Channel channel = session.openChannel("shell");
OutputStream out = channel.getOutputStream();
out.write(asciiDecimalCode); // send characters
Thanks in advance.
The escape sequence for "Arrow up" is "\u001b[A"
. \u001b
is the code for ESC (Escape).
That means while you have a single key code in JavaScript, you need to write 3 bytes to BASH to achieve the desired effect.
You can see it for yourself by typing Ctrl+VUp.
The Ctrl+V tells bash: "Don't try to interpret the next input; just insert it verbatim".
Related:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With