开发者

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
Ri开发者_Go百科ght: 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?


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜