Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!bloom-beacon!dont-send-mail-to-path-lines From: mouse@lightning.mcrcim.mcgill.EDU (der Mouse) Newsgroups: comp.windows.x Subject: Re: How do I remap the keyboard? Message-ID: <9104102309.AA00552@lightning.McRCIM.McGill.EDU> Date: 10 Apr 91 23:09:45 GMT Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 88 > We have an application that needs to redefine the keys on the > keyboard to be different from the default. It is obvious that X > contains support for this; After a fashion. The X protocol contains support for remapping the keyboard in the sense of changing the mapping between physical keys ("keycodes") and logical keys ("keysyms"). Xt, and some (most? all?) clients that use it, has/have support for mapping (logical) keys to mostly-arbitrary actions. > Two simple examples should suffice. Suppose, firstly, that I wanted > to make this keyboard's command and period keys behave like they do > on most ASNI terminals: shift+comma is '<' and shift+period is '>'. You mean they don't already? :-) > How would I do it? It seems that xmodmap should be able to do this, > but damned if I can figure out the -e '...' expression to actually > accomplish it. The result of the command > xmodmap -pk | egrep 'comma|period|less|greater' > on this system is: > 201 0x003c (less) 0x003e (greater) > 232 0x002c (comma) 0x002c (comma) > 237 0x002e (period) 0x002e (period) This is the sort of thing that is well-supported. xmodmap - << EOF keysym comma = comma less keysym period = period greater EOF or I believe the following is equivalent xmodmap -e 'keysym comma = comma less' -e 'keysym period = period greater' You may want to do something with the key as well. (Let me guess: you have a DEC keyboard. :-) > Another example is redefining a function key. [...] An example here > is that the key labeled "F5" sends the keycode 90, which is mapped > onto keysym 0xffc2=F5. You're ahead of the pack here. Most people confused by X keyboard handling wouldn't even understand that last sentence :-) > When I run a program and type an F5 at it, what it receives is the > character string: > 1B 5B 31 35 7E > which is "\e[15~" in another notation. When you type F5, what happens depends on the (X) client it's being typed at. When you say "run a program and type an F5 at it", I assume you are running a non-X-aware program from within a terminal emulator window. In that case, the mapping from keysym F5 to the string you gave is being performed by the terminal emulator, and to change it you have to coax the terminal emulator into doing what you want. This may be anywhere from easy to impossible, depending on how customizable it is. xterm, for example, makes it fairly easy; the example in the FAQ is ---------------------------------------------------------------------- Subject: 62) How do I remap the keys on my keyboard to produce a string? There is no method of arranging for a particular string to be produced when you press a particular key. The xmodmap client, which is useful for moving your CTRL and ESC keys to useful places, just rearranges keys and does not do "macro expansion." Some clients, including xterm and several X-based editors, accept a translation resource such as: xterm*VT100.Translations: #override \ F1: string("setenv DISPLAY unix:0") which permits the shorthand F1 to be pressed to reset the display locally within an xterm. However, this doesn't work across all clients. Window managers, which could provide this facility, do not yet; nor has a special "remapper" client been made available. ---------------------------------------------------------------------- Since you appear to be on a DEC machine, you may have to contend with dxterm. I would hope that dxterm has something similar; if you're lucky, it will be identical. Experiment and/or check the documentation (or just chuck dxterm and use xterm instead). der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu