Summary; keyboard remapping

David Stern (dave@davka.gsfc.nasa.gov)
Tue, 09 Dec 1997 08:11:40 -0500 (EST)

Original question:

> My old type-5 keyboard died and was replaced with a quasi-similar
> type-5 but alas some of the keys are different and I have no hardware
> documentation. I've remapped some but would like to remap the blank key
> in the upper left area (next to the "help" key) to ESC. How is this key
> referenced? What would be the line in .Xmodmap?

I received a number of suggestions to use xev which I didn't have. I found
my own solution (which others also suggested) using xkeycaps which is a
graphic frontend for xmodmap. It displays your keyboard, the keycode, keysym,
allows you to swap keys on the fly and much more.

The following are some of the other replies:

>From harvey@ncotw20.iotek.ns.ca Mon Dec 8 16:35:03 1997

****************** Here is a script I use to setup Sun
****************** Keyboards... enjoy... -H-

#! /bin/csh

set os=`uname`
set rev=`uname -r`

if ( $os == "HP-UX" ) then
exit
endif

if ( $os == "SunOS" ) then
if (( $rev == '4.1.2' ) || ( $rev == '4.1.3' ) || ( $rev == '5.5' )) then
set KEYBOARD=`/usr/local/bin/sun_kbd_type`
endif

xmodmap -e "keycode 78 = KP_F1 KP_F1 KP_Subtract"
xmodmap -e "keycode 97 = KP_F3 KP_F3 KP_Enter"
xmodmap -e "keycode 132 = KP_F2 KP_F2 KP_Add"
xmodmap -e "keycode 57 = Delete Delete KP_Decimal"

xmodmap -e "keycode 9 = Up"
xmodmap -e "keycode 11 = Up"
xmodmap -e "keycode 22 = Up"
xmodmap -e "keycode 82 = Up"
xmodmap -e "keycode 118 = Up"
xmodmap -e "keycode 122 = Up"
xmodmap -e "keycode 123 = Up"
xmodmap -e "keycode 124 = Up"
xmodmap -e "keycode 131 = Up"
if ( $KEYBOARD == SunType4 ) then
xmodmap -e "keycode 20 = KP_F4"
endif
if ( $KEYBOARD == SunType5 ) then
xmodmap -e "keycode 20 = Up"
endif
endif

unset os
unset rev
unset KEYBOARD

************ And here is a program I use to determine the
************ keyboard type ...

#include <sys/time.h>
#include <sys/types.h>
#include <sys/stream.h>
#include <sys/stropts.h>
#include <sundev/vuid_event.h>
#include <sundev/kbio.h>
#include <sundev/kbd.h>
#include <fcntl.h>

int kbd_type = 0;
int kbd_layout = 0;
char *kbd_type_str = 0;

main() {
int fd;

if ((fd = open("/dev/kbd", O_RDWR)) == -1) {
perror("opening /dev/kbd");
exit(1);
}

if (ioctl(fd, KIOCTYPE, &kbd_type) != 0) {
perror("doing ioctl KIOCTYPE");
exit(2);
}

if (ioctl(fd, KIOCLAYOUT, &kbd_layout) != 0) {
perror("doing ioctl KIOCLAYOUT");
exit(3);
}

switch (kbd_type) {
case KB_KLUNK:
kbd_type_str = "SunMicroSwitch"; /* Micro Switch 103SD32-2 */
break;
case KB_VT100:
kbd_type_str = "SunKeytronicsVT100"; /* Keytronics VT100 compatible */
break;
case KB_SUN2:
kbd_type_str = "SunType2"; /* Sun-2 keyboard */
break;
case KB_SUN3:
kbd_type_str = "SunType3"; /* Sun-3 keyboard */
break;
case KB_SUN4:
if (kbd_layout>=0x21) {
kbd_type_str = "SunType5";
} else {
kbd_type_str = "SunType4";
}
break;
case KB_ASCII:
kbd_type_str = "SunASCII"; /* ASCII terminal masquerading as keyboard */
break;
case KB_VT220:
kbd_type_str = "SunVT220"; /* VT220 */
break;
case KB_VT220I:
kbd_type_str = "SunVT220I"; /* VT220 International */
break;
default:
kbd_type_str = "Unknown";
break;
}

/*
printf("KBD Type %d\n", kbd_type);

printf("KBD Layout %d\n", kbd_layout);
*/

printf("%s", kbd_type_str);
}

-------------------------------------------------------------------------------

>From fcusack@voicenet.com Mon Dec 8 16:45:54 1997

In .Xmodmap:

keycode 22 = Escape

Your old type-5 was the "PC" type and your new one is the "unix" type.
You might also like to make the current escape key something else, eg

keycode 36 = grave asciitilde

There is a program that lets you see the keyboard names/mappings/etc. It's
called xkeycaps, available with the MIT X distribution in contrib/
probably. You can get a solaris binary from www.sunfreeware.com

-------------------------------------------------------------------------------

>From kcolagio@wc.eso.mc.xerox.com Mon Dec 8 22:02:18 1997

Below is what I use as the file to xmodmap . The key number is 22.
Note: if you use a Cybex switch, it doesn't recognize that key (at least
I haven't gotten it to...8*( ).

remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
keycode 22 = Escape
keycode 36 = grave asciitilde
keycode 49 = BackSpace

-------------------------------------------------------------------------------

From: Jens Fischer <jefi@su00330.kat.ina.de>

Hi David,

perhaps there is an easyer Solution for your keyboard problem. If you just want
to use the same keyboard mapping as on your old keyboard then you should have a
look at the dip switches located under a small piece of plastic on the back of
the keyboard. If you change the switches of the new Keyboard to the settings of
the old one you should get the desired mapping.

=-=-=-=-=-=-=-=-=- generated by /dev/dave -=-=-=-=-=-=-=-=-=-=-=-=-=-=
David Stern Flight Dynamics
dave@davka.gsfc.nasa.gov Goddard Space Flight Ctr
Building 23 Room S226 301-286-9786