pokstad
pokstad

Reputation: 3461

How do I send an arrow key in Perl using the Net::Telnet module?

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?

Upvotes: 3

Views: 3298

Answers (2)

Gavin Brock
Gavin Brock

Reputation: 5087

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)

Upvotes: 1

rjh
rjh

Reputation: 50324

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.

Upvotes: 5

Related Questions