Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Dec 2004 00:07:08 -0600 (CST)
From:      Lars Eighner <eighner@io.com>
To:        John Conover <conover@rahul.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: ALT key on console25?
Message-ID:  <20041215224126.X54401@goodwill.io.com>
In-Reply-To: <20041215214746.5288.qmail@rahul.net>
References:  <20041215214746.5288.qmail@rahul.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 15 Dec 2004, John Conover wrote:

>
> Is it possible to make the ALT key work on console25?

The console keyboard is easily mappable.  Assuming you have a
normal PC (and not some Sparc or Alpha thing about which I know
nothing), your ALT key should work right out of the box.  The
problem, if you have a problem, is that it may not do quiet what
you want.

Now there are two different things that people may mean when
they say they want ALT characters.  Some people (and
applications) want ALT-<keyboard character> to mean an
eight-bit character, which is simply the 7-bit character
with the 8th bit set.  Other people (and applications) want
ALT-<keyboard character> to send a string composed of the
escape character followed by the 7-bit character.  You
can get either behavior (or if you have a spare key, like
the Windoz key) you can get both.

Another possible problem is with ALT-<function key>, which
for the numbered F keys are usually used to switch consoles,
but which can easily be adjust to do the norm ANSI keyboard
thing that you expect with a PC.

First, to get ALT-<character> to send the eight-bit character,
use the emacs keyboard.

To get the <ESC>-character behavior you must remap the ALT
keys to "meta" (or use a spare key like Windoz as the "meta"
key.

To get the ALT-Fn keys to send the ANSI keys ( <ESC>-[-w
through <ESC>-[-{ ) you just have to switch some key definitions
around.

I will now demonstrate how each of these things works:

The keyboard maps reside in /usr/share/syscons/keymaps. 
The keymap you want to use is set in /etc/rc.conf with
a line like this:

keymap="us.emacs"

To be effective, this line must be the last of similar lines
in rc.conf.  (Essentially, the defaults are in /etc/default -
don't mess with them - and sysinstall and you use /etc/rc.conf
to make changes, and the last changes in this file win.)

Changes made in rc.conf will not be effective until or unless
you reboot.  You can use kbdcontrol to change keymaps in your
current session.

Simply changing to the emacs keyboard will get the behavoir of
sending 8-bit characters for ALT-<keyboard character>

Here is a part of the us-iso keyboard you probably installed:

#                                                         alt
# scan                       cntrl          alt    alt   cntrl lock
# code  base   shift  cntrl  shift  alt    shift  cntrl  shift state
# ------------------------------------------------------------------
   000   nop    nop    nop    nop    nop    nop    nop    nop     O
   001   esc    esc    esc    esc    esc    esc    debug  esc     O
   002   '1'    '!'    nop    nop    '1'    '!'    nop    nop     O
   003   '2'    '@'    nul    nul    '2'    '@'    nul    nul     O

See, ALT-1 simply sends 1, and ALT-! simply sends !, and that is
not what you want.

Here is the same part of the us-emacs keyboard:

#                                                         alt
# scan                       cntrl          alt    alt   cntrl lock
# code  base   shift  cntrl  shift  alt    shift  cntrl  shift state
# ------------------------------------------------------------------
   000   nop    nop    nop    nop    nop    nop    nop    nop     O
   001   esc    esc    esc    esc    esc    esc    esc    esc     O
   002   '1'    '!'    nop    nop    177    161    nop    nop     O
   003   '2'    '@'    nul    nul    178    192    128    128     O

Now see, 1 sends 1 which is character code 49, but ALT-1 sends
177, which is 49 + 128 - or in other words 1 with the 8th bit
set.  So if that is what you want (and it is probably what you
expect on a PC), just switch to the emacs keyboard).

But if you want ALT-<keyboard character> to send <ESC>-<keyboard
character>, what you want is called a meta key.  One of the best
ways to get a meta key is to map the Windoz keys to meta.

   105   meta   fkey62 fkey62 fkey62 fkey62 fkey62 fkey62 fkey62  O
   106   meta   fkey63 fkey63 fkey63 fkey63 fkey63 fkey63 fkey63  O
   107   esc    fkey64 fkey64 fkey64 fkey64 fkey64 fkey64 fkey64  O

This maps the Windoz keys to meta (and makes the Menu key an
extra esc key in case you are too lazy to reach all the way up
there to hit the usual esc key.

If you don't have Windoz keys get a new keyboard - they are
cheap - or remap one or the other of the ALT keys.

   056   lalt   lalt   lalt   lalt   lalt   lalt   lalt   lalt    O
   093   ralt   ralt   ralt   ralt   ralt   ralt   ralt   ralt    O

You can change whichever of the lalt or ralt keys to meta. 
Oh, yeah, make these change with a flat ascii edit, not a word
processor, and probably you should save the distribution
keyboard somewhere (like us.emacs.kbd.dist) before you edit).
You probably do not want to make all the alt keys into meta.


So that gets you 1) ALT-<keyboard character> sends 8-bit
character, and 2) META-<keyboard character> sends
<ESC>-<keyboard character>.

Finally we come to the function keys known as F1, F2, ... F12.
Again I am assuming an ordinary PC with a more or less PC
compatible keyboard attached.

Here's the pertenant part of the us.emacs keyboard (with a
bunch of stuff skipped so you can easily see the headers):

#                                                         alt
# scan                       cntrl          alt    alt   cntrl lock
# code  base   shift  cntrl  shift  alt    shift  cntrl  shift state
# ------------------------------------------------------------------
   000   nop    nop    nop    nop    nop    nop    nop    nop     O
# skipped stuff
   059   fkey01 fkey13 fkey25 fkey37 scr01  scr11  scr01  scr11   O
   060   fkey02 fkey14 fkey26 fkey38 scr02  scr12  scr02  scr12   O
   061   fkey03 fkey15 fkey27 fkey39 scr03  scr13  scr03  scr13   O
   062   fkey04 fkey16 fkey28 fkey40 scr04  scr14  scr04  scr14   O
   063   fkey05 fkey17 fkey29 fkey41 scr05  scr15  scr05  scr15   O
   064   fkey06 fkey18 fkey30 fkey42 scr06  scr16  scr06  scr16   O
   065   fkey07 fkey19 fkey31 fkey43 scr07  scr07  scr07  scr07   O
   066   fkey08 fkey20 fkey32 fkey44 scr08  scr08  scr08  scr08   O
   067   fkey09 fkey21 fkey33 fkey45 scr09  scr09  scr09  scr09   O
   068   fkey10 fkey22 fkey34 fkey46 scr10  scr10  scr10  scr10   O
# stuff skipped between f10 and f11
   087   fkey11 fkey23 fkey35 fkey47 scr11  scr11  scr11  scr11   O
   088   fkey12 fkey24 fkey36 fkey48 scr12  scr12  scr12  scr12   O

What this does is make ALT-Fx switch to virtual terminal x.
Probably you want ALT-Fx to send the ansi codes <ESC>-[-w
through <ESC>-[-{.  These codes are sent by fkey37 through
fkey48.

All you have to do is switch fkey37 with scr01, fkey38 with
scr02, etc.

Like this:
#                                                         alt
# scan                       cntrl          alt    alt   cntrl lock
# code  base   shift  cntrl  shift  alt    shift  cntrl  shift state
# ------------------------------------------------------------------
#Stuff skipped
   059   fkey01 fkey13 fkey25 scr01  fkey37 scr11  scr01  scr11   O
   060   fkey02 fkey14 fkey26 scr02  fkey38 scr12  scr02  scr12   O
   061   fkey03 fkey15 fkey27 scr03  fkey39 scr13  scr03  scr13   O
   062   fkey04 fkey16 fkey28 scr04  fkey40 scr14  scr04  scr14   O
   063   fkey05 fkey17 fkey29 scr05  fkey41 scr15  scr05  scr15   O
   064   fkey06 fkey18 fkey30 scr06  fkey42 scr16  scr06  scr16   O
   065   fkey07 fkey19 fkey31 scr07  fkey43 scr07  scr07  scr07   O
   066   fkey08 fkey20 fkey32 scr08  fkey44 scr08  scr08  scr08   O
   067   fkey09 fkey21 fkey33 scr09  fkey45 scr09  scr09  scr09   O
   068   fkey10 fkey22 fkey34 scr10  fkey46 scr10  scr10  scr10   O
#stuff skipped
   087   fkey11 fkey23 fkey35 scr11  fkey47 scr11  scr11  scr11   O
   088   fkey12 fkey24 fkey36 scr12  fkey48 scr12  scr12  scr12   O

And that's that.

Bonus:  Make ALT-tab and CTL-tab rotate through the virtual
screens:

   015   ht     ht     nscr   ht     pscr   137    137    137     O

Bonus bonus:  Make xterm work more or less like your new console
and make the delete keys work properly:

Add this to your .Xdefaults file:

!! xterm keymappings
*XTerm*VT100.translations:      #override \n\
         None<Key>F1: string(0x1b) string("[M") \n\
         None<Key>F2: string(0x1b) string("[N") \n\
         None<Key>F3: string(0x1b) string("[O") \n\
         None<Key>F4: string(0x1b) string("[P") \n\
         None<Key>F5: string(0x1b) string("[Q") \n\
         None<Key>F6: string(0x1b) string("[R") \n\
         None<Key>F7: string(0x1b) string("[S") \n\
         None<Key>F8: string(0x1b) string("[T") \n\
         None<Key>F9: string(0x1b) string("[U") \n\
         None<Key>F10: string(0x1b) string("[V") \n\
         None<Key>F11: string(0x1b) string("[W") \n\
         None<Key>F12: string(0x1b) string("[X") \n\
         None<Key>Insert: string(0x1b) string("[L") \n\
         Shift<Key>F1: string(0x1b) string("[Y") \n\
         Shift<Key>F2: string(0x1b) string("[Z") \n\
         Shift<Key>F3: string(0x1b) string("[a") \n\
         Shift<Key>F4: string(0x1b) string("[b") \n\
         Shift<Key>F5: string(0x1b) string("[c") \n\
         Shift<Key>F6: string(0x1b) string("[d") \n\
         Shift<Key>F7: string(0x1b) string("[e") \n\
         Shift<Key>F8: string(0x1b) string("[f") \n\
         Shift<Key>F9: string(0x1b) string("[g") \n\
         Shift<Key>F10: string(0x1b) string("[h") \n\
         Shift<Key>F11: string(0x1b) string("[i") \n\
         Shift<Key>F12: string(0x1b) string("[j") \n\
         Ctrl<Key>F1: string(0x1b) string("[k") \n\
         Ctrl<Key>F2: string(0x1b) string("[l") \n\
         Ctrl<Key>F3: string(0x1b) string("[m") \n\
         Ctrl<Key>F4: string(0x1b) string("[n") \n\
         Ctrl<Key>F5: string(0x1b) string("[o") \n\
         Ctrl<Key>F6: string(0x1b) string("[p") \n\
         Ctrl<Key>F7: string(0x1b) string("[q") \n\
         Ctrl<Key>F8: string(0x1b) string("[r") \n\
         Ctrl<Key>F9: string(0x1b) string("[s") \n\
         Ctrl<Key>F10: string(0x1b) string("[t") \n\
         Ctrl<Key>F11: string(0x1b) string("[u") \n\
         Ctrl<Key>F12: string(0x1b) string("[v") \n\
         Alt<Key>F1: string(0x1b) string("[w") \n\
         Alt<Key>F2: string(0x1b) string("[x") \n\
         Alt<Key>F3: string(0x1b) string("[y") \n\
         Alt<Key>F4: string(0x1b) string("[z") \n\
         Alt<Key>F5: string(0x1b) string("[@") \n\
         Alt<Key>F6: string(0x1b) string("[[") \n\
         Alt<Key>F7: string(0x1b) string("[ ") \n\
         Alt<Key>F8: string(0x1b) string("[]") \n\
         Alt<Key>F9: string(0x1b) string("[^") \n\
         Alt<Key>F10: string(0x1b) string("[_") \n\
         Alt<Key>F11: string(0x1b) string("[`") \n\
         Alt<Key>F12: string(0x1b) string("[{") \n\
         Meta<Key>a: string(0x1b) string("a") \n\
         Meta<Key>b: string(0x1b) string("b") \n\
         Meta<Key>c: string(0x1b) string("c") \n\
         Meta<Key>d: string(0x1b) string("d") \n\
         Meta<Key>e: string(0x1b) string("e") \n\
         Meta<Key>f: string(0x1b) string("f") \n\
         Meta<Key>g: string(0x1b) string("g") \n\
         Meta<Key>h: string(0x1b) string("h") \n\
         Meta<Key>i: string(0x1b) string("i") \n\
         Meta<Key>j: string(0x1b) string("j") \n\
         Meta<Key>k: string(0x1b) string("k") \n\
         Meta<Key>l: string(0x1b) string("l") \n\
         Meta<Key>m: string(0x1b) string("m") \n\
         Meta<Key>n: string(0x1b) string("n") \n\
         Meta<Key>o: string(0x1b) string("o") \n\
         Meta<Key>p: string(0x1b) string("p") \n\
         Meta<Key>q: string(0x1b) string("q") \n\
         Meta<Key>r: string(0x1b) string("r") \n\
         Meta<Key>s: string(0x1b) string("s") \n\
         Meta<Key>t: string(0x1b) string("t") \n\
         Meta<Key>u: string(0x1b) string("u") \n\
         Meta<Key>v: string(0x1b) string("v") \n\
         Meta<Key>w: string(0x1b) string("w") \n\
         Meta<Key>x: string(0x1b) string("x") \n\
         Meta<Key>y: string(0x1b) string("y") \n\
         Meta<Key>z: string(0x1b) string("z") \n\
         Meta<Key>1: string(0x1b) string("1") \n\
         Meta<Key>2: string(0x1b) string("2") \n\
         Meta<Key>3: string(0x1b) string("3") \n\
         Meta<Key>4: string(0x1b) string("4") \n\
         Meta<Key>5: string(0x1b) string("5") \n\
         Meta<Key>6: string(0x1b) string("6") \n\
         Meta<Key>7: string(0x1b) string("7") \n\
         Meta<Key>8: string(0x1b) string("8") \n\
         Meta<Key>9: string(0x1b) string("9") \n\
         Meta<Key>0: string(0x1b) string("0") \n\
         Meta<Key>Escape: string(0x1b) string(0x1b) \n\
         Meta<Key>exclam: string(0x1b) string("!") \n\
         Meta<Key>at: string(0x1b) string("@") \n\
         Meta<Key>numbersign: string(0x1b) string("#") \n\
         Meta<Key>dollar: string(0x1b) string("$") \n\
         Meta<Key>percent: string(0x1b) string("%") \n\
         Meta<Key>asciicircum: string(0x1b) string("^") \n\
         Meta<Key>ampersand: string(0x1b) string("&") \n\
         Meta<Key>asterisk: string(0x1b) string("*") \n\
         Meta<Key>parenleft: string(0x1b) string("(") \n\
         Meta<Key>parenright: string(0x1b) string(")") \n\
         Meta<Key>minus: string(0x1b) string("-") \n\
         Meta<Key>underscore: string(0x1b) string("_") \n\
         Meta<Key>equal: string(0x1b) string("=") \n\
         Meta<Key>plus: string(0x1b) string("+") \n\
         Meta<Key>bracketleft: string(0x1b) string("[") \n\
         Meta<Key>braceleft: string(0x1b) string("{") \n\
         Meta<Key>bracketright: string(0x1b) string("]") \n\
         Meta<Key>braceright: string(0x1b) string("}") \n\
         Meta<Key>semicolon: string(0x1b) string(";") \n\
         Meta<Key>colon: string(0x1b) string(";") \n\
         Meta<Key>apostrophe: string(0x1b) string("0x27") \n\
         Meta<Key>quotedbl: string(0x1b) string("0x22") \n\
         Meta<Key>grave: string(0x1b) string("9x96") \n\
         Meta<Key>asciitilde: string(0x1b) string("~") \n\
         Meta<Key>backslash: string(0x1b) string("0x92") \n\
         Meta<Key>bar: string(0x1b) string("|") \n\
         Meta<Key>comma: string(0x1b) string(",") \n\
         Meta<Key>less: string(0x1b) string("<") \n\
         Meta<Key>period: string(0x1b) string(".") \n\
         Meta<Key>greater: string(0x1b) string(">") \n\
         Meta<Key>slash: string(0x1b) string("/") \n\
         Meta<Key>question: string(0x1b) string("?") \n\
         <Key>Delete: string(0x7f) \n\
         <Key>KP_Delete: string(0x7f) \n\

-- 
Lars Eighner
eighner@io.com -finger for geek code-
http://www.io.com/~eighner/index.html
8800 N IH35 APT 1191 AUSTIN TX 78753-5266



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20041215224126.X54401>