Linux-CapsLock-Delay-Fixer
Linux-CapsLock-Delay-Fixer copied to clipboard
This is the WRONG way to fix the issue.
For a start - Linux is the correct way. Find a mechanical, or even an old electric typewriter. You press the Caps lock to lock it on, then you press to unlock the key and RELEASE they key to take Caps lock off.
You should use xkbcomp to adjust to 'incorrect' behaviour (as seen in Mac and Windows) where Caps Lock is deactivated on pressing, not releasing it.
To test, type slowly... ff
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.
If you want to automate this, then write a script and put it in your startup.
#!/bin/sh
xkbcomp ~/keyboardmap $DISPLAY
Put a PR to fix the script? :D
For a start - Linux is the correct way. Find a mechanical, or even an old electric typewriter. You press the Caps lock to lock it on, then you press to unlock the key and RELEASE they key to take Caps lock off.
You should use xkbcomp to adjust to 'incorrect' behaviour (as seen in Mac and Windows) where Caps Lock is deactivated on pressing, not releasing it.
To test, type slowly... ff FF FF FF ff Now try this method and do the test again.
METHOD: Start by creating a copy of your keyboard map:
xkbcomp -xkb $DISPLAY keyboardmapEdit 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 $DISPLAYNow do the typing test again. The caps lock is released when you press - and before you release the capslock key.
If you want to automate this, then write a script and put it in your startup.
#!/bin/sh xkbcomp ~/keyboardmap $DISPLAY
Finally! I have been struggling with this "feature" for years and no fix has worked for me!
I really can't thank you enough. Thanks so much!!
Nice solution. I ll update repo with your solution after some test. Or you can create pull request :)
More details on how to make a script:
#!/bin/sh
rpl='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\) \] \}'
# Create copy of kb description
xkbcomp -xkb $DISPLAY keyboardmap
# Replace CAPS
sed -i "s/key <CAPS>[^;]*/$rpl/" keyboardmap
# Apply
xkbcomp keyboardmap $DISPLAY
# Remove temp file
rm keyboardmap
@tprei the sed line in your script modifies my keyboardmap file and makes it invalid causing the script to fail with the following error:
syntax error: line 1386 of keyboardmap
last scanned symbol is: type
Errors encountered in keyboardmap; not compiled.
I have discovered this is because within the file created by xkbcomp -xkb $DISPLAY keyboardmap, the section starting with key <CAPS> is split across multiple lines like so
key <CAPS> {
type= "ALPHABETIC",
repeat= No,
symbols[Group1]= [ Caps_Lock, Caps_Lock ],
actions[Group1]= [ LockMods(modifiers=Lock), LockMods(modifiers=Shift+Lock,affect=unlock) ]
};
Since sed cannot handle multiline matching (iirc), running the sed line leads to this invalid keyboadmap file
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) ] }
type= "ALPHABETIC",
repeat= No,
symbols[Group1]= [ Caps_Lock, Caps_Lock ],
actions[Group1]= [ LockMods(modifiers=Lock), LockMods(modifiers=Shift+Lock,affect=unlock) ]
};
If we replacing sed with perl
perl -i -0777 -pe "s/key <CAPS>[^;]*/$rpl/" keyboardmap
the file is modified correctly, leading to the key <CAPS> to look like the below (as expected). This allows the script to run and complete successfully
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) ] };
Hi @ben2talk , you wouldn't happen to know either how to fix this on recent versions or how to go about solving it? This method has been broken for a while, the keyboardmap file becomes invalid.
Can't find much information about this other than this post here so if you have any directions it'd be greatly appreciated. Thanks!