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

醉酒当歌 提交于 2019-12-10 19:34:55

问题


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?


回答1:


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.




回答2:


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)



来源:https://stackoverflow.com/questions/2502197/how-do-i-send-an-arrow-key-in-perl-using-the-nettelnet-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!