Summary: mapping SUN-4 keyboard under X

From: Mark Hessling (
Date: Wed Nov 06 1991 - 17:05:56 CST

Thnaks to those who responded to my query on remapping SUN-4 keyboard
keys while running under X.
The main purpose I had was to remap the top row of function keys so that
they would return a different value when used eith the shift,control and
meta keys. I only needed this function when using xterm. As a result I
only tried the solution suggested by Larry Virden in the first posting
(following). As this gave the effect I was after I didn't attempt the
other suggestions.
Following are the postings I received; some shortened.
Mark Hessling Email:
ITC Phone: +617 875 7691
Griffith University Fax: +617 875 7877
Nathan, Brisbane QLD 4111 Australia
>From Wed Nov 6 05:51:09 1991

loadkeys only works for SunView (sigh). X11 is a different bird. There
_IS_ no _ONE_ way to do what you asked for. What you have to do is take
EACH X application and create the appropriate maps - you didnt think
x was going to make anything easy for you, did you?

For instance, as far as I can tell, you cannot in any way do what you
are wanting in mailtool, textedit, cm, shelltool or cmdtool. In xterm, it
is a piece of cake:

XTerm*VT100.translations: #override \n \
 Shift<KeyPress>Select:select-cursor-start() select-cursor-end(CLIPBOARD,CUT_BUFFER0,PRIMARY)\n\
 Shift<Key>F1: string("echo this is shift F1\n")\n\
 Ctrl<Key>F1: string("echo this is ctrl F1\n")\n\
 Meta<Key>F1: string("echo this is meta F1\n")\n\
 Alt<Key>SunF36: string("echo this is alt F11c\007")\n\
 Ctrl<Key>?: string("\177")\n\
 Shift<Key>L10: select-end(PRIMARY,CLIPBOARD,CUT_BUFFER0)\n\
 <Key>L10: start-extend() select-end(PRIMARY,CLIPBOARD,CUT_BUFFER0)\n\
 ~Ctrl ~Meta<Btn2Down>: start-extend()\n\
 ~Meta<Btn2Motion>: select-extend()\n\
 ~Ctrl ~Meta<Btn2Up>: select-end(PRIMARY,CUT_BUFFER0)\n\
 ~Ctrl ~Meta<Btn3Down>: ignore()\n\
 ~Ctrl ~Meta<Btn3Up>: insert-selection(CLIPBOARD,CUT_BUFFER0,PRIMARY)\n\
        Any<Key>F28: string(0x7f) \n \
        Any<Key>F1: string(0x1b) string("1") \n \
        Any<Key>SunF36: string(0x1b) string("[234z") \n \
        Any<Key>SunF37: string(0x1b) string("[235z") \n \
        ~Mod2<Key>KP_Equal: string(0x1b) string("[211z") \n \
        ~Mod2<Key>KP_Divide: string(0x1b) string("[212z") \n \
        ~Mod2<Key>KP_Multiply: string(0x1b) string("[213z") \n \
        Shift<Key>KP_Subtract: string(0x1b) string("[254z") \n \
        ~Mod2<Key>KP_Subtract: string(0x1b) string("[254z") \n \
        ~Mod2<Key>KP_7: string(0x1b) string("[214z") \n \
        ~Mod2<Key>KP_8: string(0x1b) string("[A") \n \
        ~Mod2<Key>KP_9: string(0x1b) string("[216z") \n \
        ~Mod2<Key>KP_4: string(0x1b) string("[D") \n \
        Shift<Key>KP_5: string(0x1b) string("[B") \n \
        ~Mod2<Key>KP_5: string(0x1b) string("[B") \n \
        ~Mod2<Key>KP_6: string(0x1b) string("[C") \n \
        ~Mod2<Key>KP_1: string(0x1b) string("[220z") \n \
        ~Mod2<Key>KP_2: string(0x1b) string("[B") \n \
        ~Mod2<Key>KP_3: string(0x1b) string("[222z") \n \
        Shift<Key>KP_0: string(0x1b) string("[247z") \n \
        ~Mod2<Key>KP_0: string(0x1b) string("[247z") \n \
        Shift<Key>KP_Decimal: string(0x1b) string("[249z") \n \
        ~Mod2<Key>KP_Decimal: string(0x1b) string("[249z") \n \
        Shift<Key>KP_Enter: string(0x1b) string("[250z") \n \
        ~Mod2<Key>KP_Enter: string(0x1b) string("[250z") \n \
        Shift<Key>KP_Add: string(0x1b) string("[253z") \n \
        ~Mod2<Key>KP_Add: string(0x1b) string("[253z") \n \
        Shift<Key>Tab: string(0x1b) string("[240z") \n \
        Ctrl<Key>Tab: string(0x1b) string("[252z") \n \
        Any<Key>Tab: string(0x09) \n \
        Shift<Key>Help: string(0x1b) string("[255z") \n \
 Any<Key>L6: start-extend() select-end(PRIMARY, CLIPBOARD, CUT_BUFFER0) \n \
 Any<Key>L8: insert-selection(CLIPBOARD)

does the job - I have a few defined for you there.

Framemaker has yet another way of doing this - I am not sure my stuff
is working so I wont impose it on you - just investigate the reference
appendices for examples.

And the list goes on - each application deciding whether they want to
provide this ability or not. Sigh.

Larry W. Virden			UUCP: osu-cis!chemabs!lwv27
Same Mbox: BITNET: lwv27@cas    INET:
Personal: 674 Falls Place,   Reynoldsburg,OH 43068-1614
America Online: lvirden

************************************************************************ >From Wed Nov 6 14:45:17 1991 ************************************************************************

Notes on assigning keys - Martin Waterworth 910903

Function and other keys on SUN keyboards, marble as the example, basically in X. OpenWindows 2.0; SunOs 4.1.1; type 4 keyboard.

dumpkeys(1) will give the physical key mappings for the native SUN mode, loadkeys(1) will put them into memory table. Another facility which allows keys to be redefined is curses(3V) - this is for System V.

Under OpenWindows and other windowing systems which have X underlying them use xev to find the keycodes of the physical keys, also the keysyms in hexadecimal will be displayed. xmodmap is the facility for changing the keysyms for a particular keycode. Note that the assignment of the keycodes is not intuitive.

On marble xterm and xev are found on /usr/openwin/demo

Below are some examples of pressing various keys, note that there is a lot of other output generated, these are the salient extracts for working out the keycodes and keysyms attached to the physical keys.

...output from xev removed... following extract 'marble' is the name of Martin's machine...

Fire up xterm with the following parameters: xterm -132 -j -s -sb -tn vt100 &

On marble the file /usr/openwin/share/include/X11/keysymdef.h contains the key capabilities and their hexadecimal translations:

... /* Cursor control & motion */

#define XK_Home 0xFF50 #define XK_Left 0xFF51 /* Move left, left arrow */ #define XK_Up 0xFF52 /* Move up, up arrow */ #define XK_Right 0xFF53 /* Move right, right arrow */ #define XK_Down 0xFF54 /* Move down, down arrow */ #define XK_Prior 0xFF55 /* Prior, previous */ #define XK_Next 0xFF56 /* Next */ #define XK_End 0xFF57 /* EOL */ #define XK_Begin 0xFF58 /* BOL */

/* Keypad Functions, keypad numbers cleverly chosen to map to ascii */

#define XK_KP_Space 0xFF80 /* space */ #define XK_KP_Tab 0xFF89 #define XK_KP_Enter 0xFF8D /* enter */ #define XK_KP_F1 0xFF91 /* PF1, KP_A, ... */ #define XK_KP_F2 0xFF92 #define XK_KP_F3 0xFF93 #define XK_KP_F4 0xFF94 #define XK_KP_Equal 0xFFBD /* equals */ #define XK_KP_Multiply 0xFFAA #define XK_KP_Add 0xFFAB #define XK_KP_Separator 0xFFAC /* separator, often comma */ #define XK_KP_Subtract 0xFFAD #define XK_KP_Decimal 0xFFAE #define XK_KP_Divide 0xFFAF ...

Find the capability you wish to use and then issue an xmodmap command.

Specific example follows for defining SUN F1, F2, F3, F4 keys at top of keyboard to be VT-100 PF1-PF4 keys in conjunction with xterm as invoked above and mods made to .xinitrc: .... # Install function key "F1" as an Open Look "Help" key # This precludes its use by applications # If your applications use F1 for anything else, comment out the following line #xmodmap -e 'keysym F1 = Help' xmodmap .xmodmaprc ...

The file .xmodmaprc should reside in the home directory and would consist of: ! ! put vt-100 function keys as f1-f4 ! keycode 12 = 0xff91 keycode 13 = 0xff92 keycode 15 = 0xff93 keycode 17 = 0xff94

NOTE that the termcap file must contain the appropriate definitions for ku, kd, kr, kl and k1-k4 eg: :ku=\EOA:kd=\EOB:kr=\EOC:kl=\EOD:kb=^H:\ :ho=\E[H:k1=\EOP:k2=\EOQ:k3=\EOR:k4=\EOS:pt:sr=5\EM:vt#3:xn:\

************************************************************************ >From Wed Nov 6 22:14:29 1991 ************************************************************************

It is nice to be able to help some other folks. Note that we have also did a bit with the xmodmap as well - We feed the following file to xmodmap: ! clear mod1 clear mod2 clear mod3 clear mod4 clear mod5 ! keycode 73 = Delete keycode 76 = Up F28 KP_8 keycode 78 = KP_Subtract ! add mod1 = Meta_L Meta_R add mod2 = Num_Lock add mod3 = Mode_switch add mod4 = F13 F16 F18 F19 F20 add mod5 = Alt_L

This allows us to use the meta keys, the caps lock, the Delete key, etc. -- Larry W. Virden UUCP: osu-cis!chemabs!lwv27 Same Mbox: BITNET: lwv27@cas INET: Personal: 674 Falls Place, Reynoldsburg,OH 43068-1614 America Online: lvirden ************************************************************************ >From Wed Nov 6 02:39:37 1991 ************************************************************************

The "loadkeys" utility only affects SunView and SunOS itself. X11 handles key presses as pure events and returns the "keycode" corresponding to the key pressed or released. There is an internal table which maps keycodes to "keysyms" for passing to applications. The "xmodmap" client lets you modify this internal table. However, key events in X are returned as names only -- to get escape sequences (or whatever) inserted when you press a key, you must use some other facitlity present in the X client you are using. For example, Sun's shelltool/cmdtool provides for mapping keys to strings via the ".ttyswrc" file; unfortunately, the documentation regarding this feature appears to incorrectly assert that 60 different function keys can be mapped: there are only 35 "function" key names in X11. Any client which is written on top of the Xt library provides a facility called "translations", which allows one to map just about any kind of event, including key presses, to procedures called "actions". An action may insert a character or string. The "xterm" terminal emulator client allows such mapping.

I am in the process of trying to find out how to get shelltool/cmdtool to let me map a greater number of keys. I'm coming to the conclusion that I'm SOL. The solution seems to be to use "xterm" instead. For what you want to do (map shifted function keys), I think *only* xterm will work.

Hope this helps,


This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:06:17 CDT