Representing arrow keys in a string

I am using Ruby’s Telnet class to establish a session with a remote
Linux machine to automate some remote administrative tasks.

The problem I am facing is this- At one point I come across a menu,
where the arrow keys have to be used to select certain options.

Is there any way to represent the arrow keys in the string that I am
sending to the remote machine?

Do let me know if you have any other ideas/suggestions?

Arindam G. wrote:

I am using Ruby’s Telnet class to establish a session with a remote
Linux machine to automate some remote administrative tasks.

The problem I am facing is this- At one point I come across a menu,
where the arrow keys have to be used to select certain options.

Is there any way to represent the arrow keys in the string that I am
sending to the remote machine?

Do let me know if you have any other ideas/suggestions?

instead of trying to make ruby know uve pushed an arrow key, think of
what command pressing a certain key does, then try to execute that
command in ruby code :slight_smile:

Michael L. wrote:

instead of trying to make ruby know uve pushed an arrow key, think of
what command pressing a certain key does, then try to execute that
command in ruby code :slight_smile:

Hi Michael,

In this case, only an option is selected in a UI menu … and no, I cant
modify/add or even read the code on the remote machine.

So I will have to send out the symbol(s) for the down arrow key over the
telnet session.

and thats where I am stuck.

Arindam G. wrote:

Is there any way to represent the arrow keys in the string that I am
sending to the remote machine?

Typing gets in irb and then hitting the four arrow keys (in the order
up,
down, right, left) (and then enter) gives me:
“\e[A\e[B\e[C\e[D\n”

HTH,
Sebastian

try irb:

STDIN.getc
… type arrow …
… type return …
=> 27 … ESC
STDIN.getc
=> 91 … [
STDIN.getc
=> 67 … C
STDIN.getc
=> 10 … (return)

My guess is : “\033[C” (\033 = octal for 27)

Gaspard

Thanks Gaspard and Sebastian,

It works!!

Arindam