[comp.unix.questions] Defining function keys

rostamia@umbc3.UMBC.EDU (Rouben Rostamian) (04/05/89)

I recently moved from a VMS system to UNIX (System V, sort of). 
Although I am generally happy with my new environment, one thing
that I really miss is the capability in VMS of defining terminal's
function keys.  Is there a way to define function keys to execute
certain commands in UNIX?  For example, can one press f17 (I have
a vt220) to execute "/bin/ps -w -u smith"?  

-- 
Rouben Rostamian
Department of Mathematics                      e-mail:
University of Maryland Baltimore Counnty       Rostamian@umbc2.bitnet
Baltimore, MD 21228                            rostamia@umbc3.umbc.edu

alex@wolf.umbc.edu (Alex Crain) (04/06/89)

In article <1869@umbc3.UMBC.EDU>, rostamia@umbc3.UMBC.EDU (Rouben Rostamian) writes:
		Is there a way to define function keys to execute
> certain commands in UNIX?  For example, can one press f17 (I have
> a vt220) to execute "/bin/ps -w -u smith"?  

	Well, sort of. Normally, the UNIX tty driver will not send a command
to the shell until the RETURN key is pressed. THis behaviour is configurable,
but the result is generally accompanied by a system slowdown.

	You can however, bind command to escape sequences using the csh 
alias feature. for example the above could be accomplished with:

	alias "[31~"	'ps -w -u smith'

and then be executed with the sequence:

	<F17><Ret>

					:alex
Alex Crain
Systems Programmer			alex@umbc3.umbc.edu
Univ Md Baltimore County		umbc3.umbc.edu!nerwin!alex

gwyn@smoke.BRL.MIL (Doug Gwyn ) (04/06/89)

In article <1869@umbc3.UMBC.EDU> rostamia@umbc3.UMBC.EDU (Rouben Rostamian) writes:
>Is there a way to define function keys to execute certain commands in UNIX?

Not normally, because all the UNIX terminal handler sees is a sequence of
ASCII codes starting with ESC, and it cannot assume that the sender of
those codes conforms to X3.64.  DEC's OS, on the other hand, has long
fully supported only DEC terminals, so their characteristics are known.
(I haven't looked at VMS recently to see if this situation has changed.)

There are some shells that have the capability of mapping escape sequences
into user-defined replacements, and many visual editors support that also.
Sometimes you can use this to map whole escape sequences (perhaps via a
series of partial mappings).

A more usual way to "package" your favorite functions on UNIX is to
define "aliases" (csh) or "shell functions" (SVR2 or later sh) or "shell
scripts" (any sh) with 1- or 2-character names that perform more elaborate
actions.  Since shell functions and scripts accept arguments they're more
general than a straight function key escape-sequence mapping.  For example,
I automatically set up my interactive SVR2-based shell so that I have an
"l" command defined:
	l(){ (set +u; exec ls -bCF $*); }

garison@mirror.UUCP (Gary Piatt) (04/07/89)

In article <1869@umbc3.UMBC.EDU> Rouben Rostamian writes:
=>
=>           ...  Is there a way to define function keys to execute
=>certain commands in UNIX?  For example, can one press f17 (I have
=>a vt220) to execute "/bin/ps -w -u smith"?                 ~~~~~~
  ~~~~~~~

Good for you!  In my own opinion, the only thing better than a DEC
vt220 is a Visual Technology v220 (because it has my name on it).

Personally, for this particular problem, I would stop trying to make
Unix do things it doesn't want to do and start making the vt220 do
things is *supposed* to do.  Check your user's manual (if you don't
have one, just email to me and I'll look this up at home); there's
a command sequence there for programming the function keys.  It's
something like:
	ESC P kn X  {string} ESC \
		kn = the key number
		X = the terminator character -- I don't remember
			what it is (it's in the manual)
		{string} = whatever you want programmed

Save a bunch of these in a file somewhere and cat the file to your
terminal during your .login.  Then, when you want one of those
functions, press <SHIFT><f17> and the terminal does the rest.

Better yet, junk the DEC and tell your boss you want a Visual 220
{andd *don't* let them sell you a 215!);  the keys can be programmed
locally and saved in non-volatile ROM.

				-Garison-


PS: if you get the 220, go into Set-up and press <CTRL><SHIFT><?>
=>
=>-- 
=>Rouben Rostamian
=>Department of Mathematics                      e-mail:
=>University of Maryland Baltimore Counnty       Rostamian@umbc2.bitnet
=>Baltimore, MD 21228                            rostamia@umbc3.umbc.edu

ok@quintus.UUCP (Richard A. O'Keefe) (04/13/89)

In article <9991@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>In article <1869@umbc3.UMBC.EDU> rostamia@umbc3.UMBC.EDU (Rouben Rostamian) writes:
>>Is there a way to define function keys to execute certain commands in UNIX?
>
>Not normally, because all the UNIX terminal handler sees is a sequence of
>ASCII codes starting with ESC, and it cannot assume that the sender of
>those codes conforms to X3.64.

If you have a terminal whose function keys can be bound to user-specifiable
strings, there is no problem.  Ann Arbor Ambassadors come to mind, there
must be lots of others.  I'm typing this on a Sun-3/50, and I have my
function keys bound to some strings I find useful.

Last year a couple of programs were posted to comp.sources.unix which
would take over terminal I/O and let you run a program underneath them;
one was called ILE, the other I forget the name of.  You could easily
adapt ILE to do function key mapping.

rbj@dsys.icst.nbs.gov (Root Boy Jim) (04/18/89)

? From: Alex Crain <alex@wolf.umbc.edu>

? In article <1869@umbc3.UMBC.EDU>, rostamia@umbc3.UMBC.EDU (Rouben Rostamian) writes:
? 		Is there a way to define function keys to execute
? > certain commands in UNIX?  For example, can one press f17 (I have
? > a vt220) to execute "/bin/ps -w -u smith"?  

? 	Well, sort of. Normally, the UNIX tty driver will not send a command
? to the shell until the RETURN key is pressed. THis behaviour is configurable,
? but the result is generally accompanied by a system slowdown.

? 	You can however, bind command to escape sequences using the csh 
? alias feature. for example the above could be accomplished with:

? 	alias "[31~"	'ps -w -u smith'

I assume you mean the "[" to be preceded by a real ESCAPE.

? and then be executed with the sequence:

? 	<F17><Ret>

? 					:alex
? Alex Crain
? Systems Programmer			alex@umbc3.umbc.edu
? Univ Md Baltimore County		umbc3.umbc.edu!nerwin!alex

I use tcsh, and "bind prefix-meta M-[", so the "F17" key actually
acts as if I typed 31 tildes. So I can (but haven't bothered to)
alias 31 tildes to whatever command I want. Bizarre!

	Root Boy Jim is what I am
	Are you what you are or what?

gordon@prls.UUCP (Gordon Vickers) (04/18/89)

> In article <1869@umbc3.UMBC.EDU>, rostamia@umbc3.UMBC.EDU (Rouben Rostamian) writes:
> 		Is there a way to define function keys to execute
>  certain commands in UNIX?  For example, can one press f17 (I have
>  a vt220) to execute "/bin/ps -w -u smith"?  
>

     YES!
     I've recently submitted a program that let's you quickly and very easily
  redefine function keys on any vt[23]xx .  The program, keydef, allows you
  to maintain one or more files containing definitions for the function keys.
  I find having definition files based upon which application I want to run
  is very convenient.
     The files are created with your favorite editor in a very simply format.
  The program allows for mapping \r, \n, \t to 'return', 'newline', and 'tab'.
  It also allows mapping two charector sequences that begin with a carrot (^)
  into the appropriate control charector.
     As an additional aid, the program will allow redefining a single key
  straight from the command line. This is very helpful when the application
  allows shell escapes as in vi(1).  It's real nice to escape from vi and
  program a key for something you'll need only for a particular session.
     I've recently summitted keydef to comp.sources.unix .  If you don't
  see it posted within the next couple of weeks, drop me a line and I'll
  email it to those interested.
     Those interested may also wish to keep an eye on comp.sources.misc
  for the keydef posting since that may be a more appropriate place for it.

Gordon Vickers 408/991-5370 (Sunnyvale,Ca); {mips|pyramid|philabs}!prls!gordon
------------------------------------------------------------------------------
Every extinction, whether animal, mineral, or vegetable, hastens our own demise.