[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Representing arrow keys in a string

Arindam Goswami

9/17/2007 6:48:00 AM

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?
--
Posted via http://www.ruby-....

5 Answers

Michael Linfield

9/17/2007 6:59:00 AM

0

Arindam Goswami 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 :)
--
Posted via http://www.ruby-....

Arindam Goswami

9/17/2007 8:34:00 AM

0

Michael Linfield 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 :)


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.
--
Posted via http://www.ruby-....

Sebastian Hungerecker

9/17/2007 9:09:00 AM

0

Arindam Goswami 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
--
Jabber: sepp2k@jabber.org
ICQ: 205544826

Gaspard Bucher

9/17/2007 9:33:00 AM

0

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

Arindam Goswami

9/18/2007 10:13:00 AM

0

Thanks Gaspard and Sebastian,

It works!!

Arindam
--
Posted via http://www.ruby-....