Caps lock turns on/off only on release

Reporting back to say that it worked like a charm. Perfect solution! You’re the man. Also thanks to Ben on the Manjaro forums for providing the answer. I’m leaving a copy of the answer here just in case.

Manual Method:

Start by creating a copy of your keyboard map:

xkbcomp -xkb $DISPLAY keyboardmap

Edit the exported file (keyboardmap) and enter the text (find the section starting with key and paste over it)

key <CAPS> { repeat=no, type[group1]="ALPHABETIC", symbols[group1]=[ Caps_Lock, Caps_Lock ], actions[group1]=[ LockMods(modifiers=Lock), Private(type=3,data[0]=1,data[1]=3,data[2]=3) ] };

To apply your edited keyboard, file you do this:

xkbcomp keyboardmap $DISPLAY

Now do the typing test again. The caps lock is released when you press - and before you release the capslock key.

Automated Method (better imo):

The manual method works, but it’s a temporary fix. Every time you restart you’ll lose these changes and will have to run the commands again…

It’s possible to automate this whole process though!!

Put the following code in a file:

#!/bin/bash

# Create a copy of the current keyboard map
xkbcomp -xkb $DISPLAY ~/keyboardmap

# Define the replacement text
replacement_text='key <CAPS> { repeat=no, type[group1]="ALPHABETIC", symbols[group1]=[ Caps_Lock, Caps_Lock ], actions[group1]=[ LockMods(modifiers=Lock), Private(type=3,data[0]=1,data[1]=3,data[2]=3) ] };'

# Use sed to replace the specific line in the keyboardmap file
sed -i 's/key <CAPS> {         \[       Caps_Lock \] };/'"$replacement_text"'/' ~/keyboardmap

# Apply the edited keyboard map
xkbcomp ~/keyboardmap $DISPLAY

Save this script as caps_fix.sh and make it executable by running:

chmod +x modify_keyboard.sh

To automate this script at startup, you can add it to your startup applications or include it in your shell profile script (e.g., .bashrc or .bash_profile). Alternatively, you can use your desktop environment’s startup applications manager.

3 Likes