Solved

Escape codes for function keys in a telnet session

Posted on 2011-03-16
5
2,082 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle Finace 3 96
How to Insert a File Using Text Editor 9 102
How to use pyenv 4 83
awk sed 8 108
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

749 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