[nycbug-talk] alt (meta) key on console?

Jeff Quast af.dingo at gmail.com
Mon Mar 20 20:29:55 EST 2006


On 2/16/06, Yusuke Shinyama <yusuke at cs.nyu.edu> wrote:
> Hi, could anyone tell me how to make
> the Alt (or Meta) key work on the FreeBSD console?
> My bash key bindings work on xterm,
> but they ignore all Alt- keys on the console.
>
> Thank you,
> Yusuke

What you need is "Meta sends escape" on the console.

You can enable this in xterm by holding meta_L (left alt key) and
pressing the left mouse button on an xterm.

On OpenBSD, I was able to produce the behavior you may desire on the
console with the command:
$ wsconsctl keyboard.map+="keycode 56=Cmd2 Escape"

Though it doesn't behave very well.

Since you are using FreeBSD, you'll need to use kbdmap or kbdcontrol.

Be warned! The left alt key is already binded to a very important function!

You might also try binding it to Meta_L. I tried here, but it didn't
work. I suspect some stty magic needs to be involved as well.

Some people bind the _right_ alt key as meta/escape instead. I suspect
you may be an ex-DOS user and you wouldn't feel comfortable with that.

I could rant for pages about how using the escape as a modifier is a
gross idea, but here is only half of one:

Anybody who has programmed interactive keyboard input with ansi escape
sequences has probably gone grumpy more than once escape sequences.
Using select() on stdin after an escape is found with a timeout of
~250ms to see if a 'sequence' comes or not is horrish. The result is
the actual escape key can sometimes take half a second to actually
escape a menu, or pressing an arrow key can escape you all the way out
of a series of menus.
Escape modifiers drive me absolutely nuts as both a programmer and a
user. It drives me even more nuts when alternate input keys are not
provided (hjkl anyone??)
Escape has been misused in the terminal world for so long now that
most people just press escape and type in the sequence manually,
especially since most programs don't use select() at all and are very
forgiving about an escape sequence taking more than a quarter of a
second.


You will see most new programs now use a <CTRL> sequence as a
modifier.  CTRL+a always sends 0x01 going back probably as far as
teletypes (I am not old enough to say for sure).

In short: If you are vi handy, I recommend you try to learn vi input
mode instead of mapping new keys to do things vi input mode most
likely already does.

If you are not vi hand (shame on you), try to re-map your keys to use
<CTRL> only.

You will thank yourself for using <CTRL> instead of <META> when you
login from another terminal and none of your bindings work and you
play the "enable meta sends escape" game on the terminal you're on all
over again.

By the way, how are you mapping the keys? .inputrc ?




More information about the talk mailing list