views:

258

answers:

2

Using the Perl module Net::Telnet, how do you send an arrow key to a telnet session so that it would be the same thing as a user pressing the down key on the keyboard?

use Net::Telnet;
my $t = new Net::Telnet();
my $down_key=?; #How do you send a down key in a telnet session?
t->print($down_key);

This list of VT102 codes says that cursor keycodes are the following:

Up:    Esc [   A
       033 133 101
Down:  Esc [   B
       033 133 102
Right: Esc [   C
       033 133 103
Left:  Esc [   D
       033 133 104

How would I send these in telnet? Are these codes the same as an arrow key pressed at the keyboard?

+4  A: 

Try printing "\e[B". These codes are indeed the same - try running the Bourne shell sh without readline support and hit the up/down arrows, you'll see something like ^[[A where ^[ represents the escape character.

rjh
I have seen that script before and it does not contain any obvious mention of sending arrow keys. There might be some confusion here, VT102 deals with tracking the movement of the cursor in order to repaint portions of the screen. For my purposes I don't care about the cursor, I simply want to send the keyboard code for an arrow key. I may be wrong, if so, do you have a sample of VT102 being used to send an arrow key (not cursor movement)?
pokstad
Sorry, the screen-scraping tag led me to suggest VT102.
rjh
No worries, I ran out of good tags to attach to this question. I'll try your suggestion and give credit as soon as I can verify :D
pokstad
+1  A: 

Some programs expect SS3 escapes, rather than CSI. If "\e[A" and friend don't work, try:

%ss3 = (
   up    => "\eOA",
   down  => "\eOB",
   right => "\eOC",
   left  => "\eOD",
);

(those are upper case letter o's, not zeros)

Gavin Brock