Solved

Escape codes for function keys in a telnet session

Posted on 2011-03-16
5
1,943 Views
Last Modified: 2012-05-11
I am connecting to a box via telnet that is running Operating System: SCO 5.07.

This telnet session is automated by a python script using the python TelnetLib library.  I need to be able to send function key and arrow key presses programatically with python through the telnet session.

The key presses I need include the up down arrows, and basically F1 through F10.  I have been unable to get this to work properly so my question is 2 fold.

1.  How can I determine what I need to send for example an F3 key press?

2.  In the python I do a telnet.write()  what do I put in there to properly send the command across?

Thanks,
0
Comment
Question by:Mr_Oz
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
LunarNRG earned 350 total points
ID: 35151605
1. I believe this may depend on other factors in your environment, but if you fire up the python interactive interpreter in a terminal on a *nix system, type a single or double quote, type CTRL+V (literal escape)[1], the key for which you want to determine the value, end with the same type of quote that you started with, and hit ENTER. The result will most likely be the value you need to pass to telnet.write(). For example ...

>>> # typing: ', CTRL+V, F1, ', ENTER
>>> '^[OP'
'\x1bOP'
>>> # typing: ', CTRL+V, F2, ', ENTER
>>> '^[OQ'
'\x1bOQ'

Open in new window


2. Here are the results from _my_ system:

F1 => '\x1bOP'
F2 => '\x1bOQ'
F3 => '\x1bOR'
F4 => '\x1bOS'
F5 => '\x1b[15~'
F6 => '\x1b[17~'
F7 => '\x1b[18~'
F8 => '\x1b[19~'
F9 => '\x1b[20~'
F10 => '\x1b[21~'
F11 => '\x1b[23~'
F12 => '\x1b[24~'
Up Arrow => '\x1b[A'
Down Arrow => '\x1b[B'

[1] From http://en.wikipedia.org/wiki/Control-V

Unix interactive terminals use Control-V to mean "the next character should be treated literally" (the mnemonic here is "v is for verbatim"). This allows a user to insert a literal Control-C or Control-H or similar control characters that would otherwise be handled by the terminal. This behavior was copied by text editors like vi and Unix shells like bash and tcsh, which offer text editing on the command line.

0
 
LVL 8

Expert Comment

by:LunarNRG
ID: 35151716
Also, don't forget to use an appropriate line ending, where you would hit the enter key interactively. For telnet I believe the line endings should be '\r\n' (CRLF).
0
 
LVL 1

Author Comment

by:Mr_Oz
ID: 35152077
Unfortunately the box I am telneting into does not have python :(  I will try some of your suggestions though.
0
 
LVL 9

Assisted Solution

by:svs
svs earned 150 total points
ID: 35152190
These key codes should be in the terminfo (terminal definition) database; this database is indexed by terminal name, which is commonly stored in TERM environment variable.

You should be able to get current terminal definition with 'infocmp' command on the SCO box.
0
 
LVL 1

Author Closing Comment

by:Mr_Oz
ID: 35156530
Thanks I think a combination of these 2 answers should get me going.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Viewers will learn how to properly install and use Secure Shell (SSH) to work on projects or homework remotely. Download Secure Shell: Follow basic installation instructions: Open Secure Shell and use "Quick Connect" to enter credentials includi…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now