7

Because I now and then need to use scandinavian letters despite using US Dvorak as my layout, I would like to use Caps Lock as a compose key. (I don't need Caps Lock at all, I'm not a forum troll)

How would one accomplish this?

Using Linux Mint 17 with xfce, if that makes a difference.

For the record, I am the only user of this PC, and would prefer to have this be the system default, mainly in xorg, but also in tty if that's not too much drudgery.

2
  • The solutions for X and tty will most likely be quite different.
    – Fabian
    Apr 8, 2015 at 18:26
  • @Fabian Noted, thanks. Question updated accordingly
    – Jarmund
    Apr 8, 2015 at 18:54

2 Answers 2

14

X11 (classic)

Run the program xev from a terminal to see the keycode sent by the CapsLock key. That's the number just after keycode on the third line from the KeyPress event line corresponding to pressing the key. On a PC, the keycode is 66.

Create a file called .Xmodmap in your home directory and add the line

keycode 66 = Mode_switch
clear Lock

Mode_switch is the weird name that X11 gives to Compose. clear Lock is necessary to avoid the key occasionally acting like Caps Lock even though it isn't Caps Lock (Lock is the Caps Lock modifier, and some applications behave a bit strangely when modifier declarations and keysym declarations aren't consistent). Alternatively, you can use the lines

keysym Lock = Mode_switch
clear Lock

which causes any key currently sending Caps Lock to be rebound to sending Compose instead. Either way, you need to arrange for the command

xmodmap ~/.Xmodmap

to be executed when your session starts. This is a common convention, but not all combinations of distribution/desktop environment do it automatically. If yours doesn't, add the command to the list of commands executed at the session start (in the XFCE4 configuration editor, go to “Session and Startup” → “Application Autostart” and add that command).

X11 (XKB)

XKB is neater and more powerful, but more cumbersome to use in general than xmodmap. There is a preset in the standard configuration to do what you want, so it's easy in your case: run the following command:

setxkbmap -option compose:caps

See the previous section for how to run this command when your session starts.

Linux console

Find out the keycode of the CapsLock key. Run showkey on a text console, press CapsLock, then wait 10 seconds for showkey to exit. On a PC, the keycode is 0x3a. You need to have the following line in your console keymap file:

keycode 0x3a = Compose

The default console keymap file is /etc/console/boottime.kmap.gz on Debian with the console-tools package. It may be a different file under Mint; this is the file that loadkeys is invoked on in the boot scripts. If you prefer, you can leave the distribution-provided files intact, create a file with the line above, and run loadkeys /path/to/your/file.kmap from /etc/rc.local.

3
  • I tried the keysym method. While xev afterwards tells me that keycode 66 now corresponds to Mode_switch, it did nothing. What worked for me in X11 in the end was this: setxkbmap -option compose:caps. The console approach worked like a charm.
    – Jarmund
    Apr 9, 2015 at 0:27
  • Thank you very much for this answer. I don't know why this was so hard to do. Other solutions either don't remove the default behaviour of caps lock or somehow bound my b key to escape instead.
    – Marcel
    May 10, 2017 at 19:35
  • 1
    The xkb method can also be persisted through x.org.conf by adding Option "XkbOptions" "compose:caps" to the appropriate section. It bears mentioning that this is going to re-map caps lock for all users. Nov 11, 2017 at 14:41
0

Just a note: In particular, XFCE lets you configure CapsLock per Settings:

enter image description here

Switch to the 'Layout' tab, and disable 'Use system defaults'. Under 'Compose Key', select Caps Lock.

This will:

  • Disable the CapsLock LED (if present)
  • Disable the CapsLock function
  • Enable the CapsLock as Compose key

I had never seen this option before, so this might be for recent XFCEs (4.16 in my case).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .