Keyboards and X

This discussion only applies to the behaviour of your keyboard when using X.
It applies in differant forms to X-Terminals,  Macs or Windows machines running some kink of a an X emulator such as MacX and unix boxes.

The invaluable tool is xev . You start this up in an an xterm window.  Put the mouse in the xev window and hita key,. You will get a string of stuff in the original xwindow that looks like this.

KeyRelease event, serial 30, synthetic NO, window 0x4c00001,
    root 0x25, subw 0x0, time 2252585519, (142,150), root:(387,235),
    state 0x0, keycode 22 (keysym 0xff08, BackSpace), same_screen YES,
    XLookupString gives 1 characters:  "

The vital pieces of information are the "keycode"  and the "keysym"  .  These codes and symbols are assingedto the specific keyboard that you are using by the specific X-driver that is controlling it. The driver is running on the machine that is running X (server)  (i.e. the X-terminal, Mac or  PC software) not on the machine that is displaying stuff in the windows (client).  Two keys that report the same "keycode"  are physically equivalent to each other and there is nothing that you can do without changing either the server software or the keyboard.

You can reconfigure the relation between the  "keycode"  and the "keysym"   using software running on the client.  I am now assuming that the client is a unix machine. The tool is a program called
xmodmap.  Here is an example,  if you run the command
xmodmap  -e "keycode 22=Delete"
and run xev  again hitting the same key you will get

KeyPress event, serial 31, synthetic NO, window 0x4c00001,
    root 0x25, subw 0x0, time 2252683349, (103,77), root:(348,162),
    state 0x0, keycode 22 (keysym 0xffff, Delete), same_screen YES,
    XLookupString gives 1 characters:  ""

This matters becuase the client interprets what to do when the key is struck by the "keysym" .
In this example the action of the key in question "22"  is changed from "Backspace" ( i.e.  delete the character to the left of  the cursor) to "Delete" (i.e. delete the character to the right of the cursor).

If you have got the basic idea you can now reconfigure your keypad my making a file called
in your home directory with lines like
keycode 22=Delete
in it and putting
xmodmap .xmodmaprc
in your .bashrc file

If you want to map the keypad to do other task, you will have to do more work. I will no explain how to use the edt-tpu feature in emacs. Before you start make sure that all the keys that you want to use  have unique "keycode"  's associated to them.  If they do, then make sure that all the ones that you want to use have a "keysym " defined.  The ones to watch out for an function keys and the keys on the top row of the keypad. I had to define several of these. Use xmodmap to do this. Here is my .xmodmarc file

keycode 77=KP_F1
keycode 112=KP_F2
keycode 63=KP_F3
keycode 82=KP_F4
keycode 111=F13
keycode 22=BackSpace
keycode 78=F14
keycode 110=F15

Do not use this without cheking it using the above proceedure    When all the keys have a unique  "keysym ", start up emacs  using
emacs -f tpu-edt
or modify your .emacs file. You will the be prompted to hit keys and a file will be created that you can load automatically when you use emacs on subseqent occations.