?
Solved

Escape codes for function keys in a telnet session

Posted on 2011-03-16
5
Medium Priority
?
2,210 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 1400 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 600 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month13 days, 17 hours left to enroll

800 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