== The old-fashioned and modern ways to remap keys in X (some notes) As I [[mentioned recently XBackspaceShift]], I've been remapping my keyboard in X for [[a very long time DeleteBackspaceSplit]]. In all of this time, I've been using the traditional and now old fashioned way of doing this, namely _xmodmap_. Xmodmap is now a deprecated mechanism, although it still works; these days you usually want to be remapping keys with _setxkbmap_. You might wonder why X has two different programs for this. As you could guess, it's the [[usual ../sysadmin/XCutAndPasteHistory]] [[reason XFontTypes]]; X added a new system for handling keyboard remapping without removing the old one (because X never removes anything). Xmodmap uses the old system, which I believe has been in X since at least the start of X11, while setxkbmap uses the new system, [[the X KeyBoard extension https://en.wikipedia.org/wiki/X_keyboard_extension]]. (Well, 'new' is relative here. XKB apparently dates from 1996, almost two decades ago. I was a little bit surprised to find that out, since I hadn't heard of it myself until recently. This is probably the hazard of having become set in my X ways a very long time ago.) I'm not the right person to write up a big evaluation of the two mechanisms against each other, because up until recently I hadn't looked into XKB and _setxkbmap_ at all (and even now I only know a bit). So from my limited perspective, the big difference between the two is that _xmodmap_ offers relatively simple and direct low-level control for weird operations while _setxkbmap_ gives you simple ways to do most of what you often want, provided that you can work out the right arguments. To show what I mean by this, here is more or less the _xmodmap_ magic needed to swap Backspace and Delete keys and to make CapsLock act as a Control key: .pn prewrap on > keysym BackSpace = Delete > keysym Delete = BackSpace > > remove Lock = Caps_Lock > keycode 0x42 = Control_L > add Control = Control_L You put this in a file and then run '_xmodmap FILE_' and magic happens. By contrast, here is the _setxkbmap_ command needed to make CapsLock act as a Control key and make the right Windows key act as Compose: > setxkbmap -option ctrl:nocaps -option compose:rwin You will notice that I have not shown you how to swap Backspace and Delete with _setxkbmap_. That's because that particular change is not among the predefined changes that XKB supports and once you venture outside of those predefined changes, things become rather complicated. (The predefined changes themselves are documented in the _xkeyboard-config_ manpage. The files that define what these options and so on mean are all found under _/usr/share/X11/xkb_; see for example _/usr/share/X11/xkb/symbols/ctrl_. If you look at these files, you'll see that XKB configuration is, well, intricate.) Because _setxkbmap_ fits my needs right now ([[now that I'm not swapping Delete and Backspace XBackspaceShift]]) and because it's apparently the more approved-of way these days, I've switched from _xmodmap_ to _setxkbmap_. I probably would not have changed over if I was doing anything that _setxkbmap_ couldn't handle through its existing options for _-options_; while more sophisticated things are possible, they appear to be a lot of work. The ArchLinux wiki has some nice references on [[Keyboard configuration in Xorg https://wiki.archlinux.org/index.php/Keyboard_configuration_in_Xorg]], [[xmodmap https://wiki.archlinux.org/index.php/Xmodmap]], and [[the X KeyBoard extension https://wiki.archlinux.org/index.php/X_KeyBoard_extension]]. While I accumulated a bunch of additional links while I was looking into _setxkbmap_, I'm not going to put any of them here because I don't know enough to assess their quality and whether they're up to date.