Solved

Escape codes for function keys in a telnet session

Posted on 2011-03-16
5
2,012 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Required to Read Linux Security Settings and User Permissions 13 129
Difference of import usage in Python 1 68
ssh setup on Cisco swith 11 65
wipe a usb using python 5 45
We all know how boring and exhausting it is to transfer huge web projects developed locally to a webserver simply via FTP. The File Transfer Protocol is a really nice solution if you need to transfer small amounts of files, but if you're plannin…
Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

785 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