26

I have an X11 program that grabs caps-lock, and uses it. The problem is, I want to disable the regular caps-lock toggling, but doing so seems to disable the key.

So whatever X11 gets for a caps-lock keypress, it must still get (no disabling the key, or remapping it to some other key), but without anything translating the keypress into a caps-toggle (which might be at the kernel level?).

I tried changing the scancode, but this just remapped the key. I've removed the capslock entry with xmodmap too, but this also disabled caps.

How can I tell the kernel to ignore the caps-key (wrt its regular functionality), but still pass along the message to X?

Just to add a bit more detail:

The 'program' I'm trying to run is humanised 'enso'. When there is no key I get the error "CRITICAL:root:Couldn't find quasimode key". When there is no error, I can use enso with caps, but sofar haven't figured out how to disable caps functionality while enso is still able to get at it.

Volker Siegel
  • 17,283
Chris2048
  • 601
  • Please provide details as to what you tried, i.e. the exact xmodmap expressions. Without details we can't tell whether you knew what to do and did it wrong, or whether you did it right but the code failed for some other reason. Also give us the OS you're using because some have keycode processing that occurs below the X server level. – Kyle Jones May 12 '13 at 00:37
  • @Kyle I tried "remove Lock = Caps_Lock", and then " keycode 66 =" (which was mapped to CapsLock). I'm running ubuntu 12.10 on a 64bit machine. – Chris2048 May 12 '13 at 02:36
  • Another possibility is to remap to another key. setxkbmap -option ctrl:nocaps remaps to Control_L, for example. – Chris Down May 12 '13 at 04:42
  • Are saying you'd be OK if we could give you a way to remap the caps-lock to say the control key or is that not what you're after? As it stands this question is kind of confusing, it would really go a long way if you added specifics into the question of what you've tried so far. – slm May 12 '13 at 05:01
  • Just so we're clear too, there is a feature in Ubuntu 12.10 where you can make caps-lock an additional control key. Is this what you're thinking when you say "remapping"? Here's a screenshot of the dialog: http://www.flickr.com/photos/11708996@N00/3010939023/ – slm May 12 '13 at 05:05
  • @slm remapping is no good if x11 doesn't get a signal that this key has been pressed, I'm not looking to change the function of my caps-key, I'm looking to disable it while still making it grabbable as a caps key. – Chris2048 May 12 '13 at 12:47
  • @"Chris Down" this remapping would mean the x11 program would not find the key. – Chris2048 May 12 '13 at 12:47
  • @slm I saw an option to "make caps-lock and additional control kut keep Caps-Lock keysym", but I'm not sure how to do this outside an ubuntu wm (a wm compatible with gnome-control-center), if this does work; I'm not sure because in the gnome environment, something else has already grabbed the key, so I can't test it, but "keeping the keysym" sounds like it might be the right solution? – Chris2048 May 12 '13 at 12:49
  • Let me know about my answer using "caps:none" – slm May 12 '13 at 13:54
  • @slm 'caps:none' cause the key not to be found. I hoped the question would reveal to me at which layer the action (caps toggle) was being done, but I might have to step throuhg the enso source-code instead :-| – Chris2048 May 12 '13 at 15:12
  • I would explore the other options in the xorg.lst file I mentioned in my answer! – slm May 12 '13 at 15:19
  • @Gilles There is no Preferences command; Maybe this applies to the windows version? – Chris2048 May 13 '13 at 20:27

4 Answers4

31

I think I have a technique for disabling the toggling of the Capslock key but not completely disabling the key all together, or remapping it to another key on the keyboard.

If you use the command:

setxkbmap -option caps:none

The keyboard will no longer toggle. I've confirmed this on my laptop running Fedora 14, the LED no longer lights up, and normal Capslock functionality is gone.

However using xev still shows that the key is being pressed:

$ xev
...
...
KeyPress event, serial 35, synthetic NO, window 0x6800001,
    root 0xb1, subw 0x0, time 261504852, (167,-15), root:(353,268),
    state 0x10, keycode 66 (keysym 0xffffff, VoidSymbol), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 35, synthetic NO, window 0x6800001,
    root 0xb1, subw 0x0, time 261504971, (167,-15), root:(353,268),
    state 0x10, keycode 66 (keysym 0xffffff, VoidSymbol), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False
    ...

So the key being pressed events are still left intact for other applications to pick them up.

setxkbmap

The file /usr/share/X11/xkb/rules/xorg.lst contains the complete list of what options you can give to setxkbmap.

Grepping through this file for "cap" I noticed this line:

caps:none            CapsLock is disabled

There are other values in this file so if this isn't what you're after perhaps one of those alternate values would suite instead.

$ grep cap /usr/share/X11/xkb/rules/xorg.lst
  grp:caps_switch      CapsLock (while pressed), Alt+CapsLock does the original capslock action
  grp:caps_toggle      CapsLock
  grp:shift_caps_toggle Shift+CapsLock
  grp:shift_caps_switch CapsLock (to first layout), Shift+CapsLock (to last layout)
  grp:alt_caps_toggle  Alt+CapsLock
  lv3:caps_switch      CapsLock
  lv3:caps_switch_latch CapsLock (chooses 3rd level, latches when pressed together with another 3rd-level-chooser)
  ctrl:nocaps          Make CapsLock an additional Ctrl
  ctrl:swapcaps        Swap Ctrl and CapsLock
  grp_led:caps         CapsLock
  caps                 CapsLock key behavior
  caps:internal        CapsLock uses internal capitalization. Shift "pauses" CapsLock
  caps:internal_nocancel CapsLock uses internal capitalization. Shift doesn't affect CapsLock
  caps:shift           CapsLock acts as Shift with locking. Shift "pauses" CapsLock
  caps:shift_nocancel  CapsLock acts as Shift with locking. Shift doesn't affect CapsLock
  caps:capslock        CapsLock toggles normal capitalization of alphabetic characters
  caps:numlock         Make CapsLock an additional NumLock
  caps:swapescape      Swap ESC and CapsLock
  caps:escape          Make CapsLock an additional ESC
  caps:backspace       Make CapsLock an additional Backspace
  caps:super           Make CapsLock an additional Super
  caps:hyper           Make CapsLock an additional Hyper
  caps:shiftlock       CapsLock toggles Shift so all keys are affected
  caps:none            CapsLock is disabled
  compose:caps         CapsLock
  shift:breaks_caps    Shift cancels CapsLock
  shift:both_capslock  Both Shift-Keys together toggle CapsLock
  shift:both_capslock_cancel Both Shift-Keys together activate CapsLock, one Shift-Key deactivates

References

slm
  • 369,824
  • 6
    If you accidentally run the command with your capslock on, you can reset xkbmap by running setxkbmap -option "". – Nemo Aug 15 '14 at 18:29
  • It shows up in xev, but doesn't really work in the Valve Source 2 engine. – Velkan Dec 17 '18 at 19:20
  • 2
    @Nemo I love you, I keep running this by mistake because I have a hotkey for when I connect an external keyboard, and you saved me from having to reboot every time. – Stavros Korokithakis Jan 07 '20 at 18:20
1

This is very similar to the answer I gave for another question. This snippet of xkb code should do the trick.

partial modifier_keys
xkb_symbols "capsoff" {
    key <CAPS> {
        type[Group1] = "ONE_LEVEL",
        symbols[Group1] = [ Caps_Lock ],
        actions[Group1] = [ NoAction() ]
    };
};
billyjmc
  • 513
  • 1
    where should this go ? I've been looking at this kind of snippets for 10 minutes without figuring it out. Does it have to be part of a more complete file or can it stand alone and apply to the default config ? – Nikana Reklawyks Jan 26 '17 at 09:47
1

If you don't want the Caps Lock key to have its usual effect, you can turn off the Lock modifier, while retaining the Caps_Lock keysym.

xmodmap -e 'clear Lock'
0

I used to use the method described by @slm but (at least on KDE Plasma using KDE Neon) this stopped working at some point.

What did the trick though was a setting inside KDE as decribed here: https://askubuntu.com/a/439230/626920

Raven
  • 703