Skip to Content.
Sympa Menu

baslinux - [BL] Notes on X11 keyboard mapping

baslinux AT lists.ibiblio.org

Subject: Baslinux mailing list

List archive

Chronological Thread  
  • From: Erkki Ruohtula <ruohtula AT netscape.net>
  • To: baslinux AT lists.ibiblio.org
  • Subject: [BL] Notes on X11 keyboard mapping
  • Date: Mon, 12 May 2003 17:04:39 -0000

Someone asked about the xmodmap file syntax. Maybe that got sorted
out but reading the list I get the feeling the following might be useful
for some people new to Linux and X11.

I haven't yet tried to use X11 on Basiclinux, but I have
tinkered with X11 keyboard mappings on various other unixlike platforms,
so maybe I can offer some hints on how to get a keyboard
to behave.

The generals idea in X11 is that when you hit a key, it sends a "keycode"
to the X11 server. These are hardware dependent. X11 toolkit libraries
and applications normally do not use them (that would make them hardware-
dependent). Instead the X11 server converts the keycodes to "keysyms"
which can be seen as a hardware-independent description of what key was
hit. The X11 programs then act on these.

The xmodmap program can be used to manipulate the keycode-to-keysym
mapping. This is usually the best way to make a key change behavior,
because it affects all X11 programs (but sometimes you want a key
remapping to affect only a particular program, and then you have to use
something specific to the program, like setting a resource string for
xterm).

The main problem with redefining keysyms is figuring out what key
produces which keycode. X11 has a program called "xev" that is a
help here. (Unfortunately some Linux distributions omit it, I don't know
if Slackware 7.1 has it). Create a xterm window and type "xev" there.
Don't put it in the background.
The xev program creates a window that just contains a square
Make the window have the keyboard focus (click it or just move mouse
there, depending on how your window manager is set up) and hit keys.
You will see text lines like:

MotionNotify event, serial 27, synthetic NO, window 0x2a00001,
root 0x3e, subw 0x0, time 3486608963, (115,115), root:(119,135),
state 0x0, is_hint 0, same_screen YES

appear in the xterm window. They list "events" that the xev program
gets from X11 (it is very educational to see how they correspond
to mouse operations!). Stop your mouse and hit the keys you are interested
in. You see something like this:

KeyPress event, serial 27, synthetic NO, window 0x2c00001,
root 0x3e, subw 0x0, time 3486777276, (107,171), root:(111,191),
state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
XLookupString gives 1 characters: "a"

KeyRelease event, serial 27, synthetic NO, window 0x2c00001,
root 0x3e, subw 0x0, time 3486777348, (107,171), root:(111,191),
state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
XLookupString gives 1 characters: "a"

This was for hitting the A key. You see it has keycode 38. Use this to
get the codes for the keys you want to remap. Then go to the xterm and hit
ctrl-C to kill the xev program.

Then you can make a file with a line like

keycode <keycode> = <unshifted> <shifted>

where <keycode> is the keycode, <unshifted> is the keysym it sends by
default and <shifted> when shift is down. Actually there can be at least
for some keys added keysyms for AltGR down and Shift-AltGr down, but
you don't need to specify them and I am not sure if they work in all
keyboards or X11 servers. The bit on modifier declarations
is not quite clear to me yet. Should investigate.

You can get a textual dump of your current keymap by typing

xmodmap -pke

This gives you an idea of what keysym names there are (and keycodes
as well).

I hope the above is useful to someone, and not totally wrong...

Erkki

PS: I read this lists from the digests and not very often,
so if you comment on the above, I will probably not respond until
after a day or two.









Archive powered by MHonArc 2.6.24.

Top of Page