You are not logged in.

#1 2023-07-28 20:53:06

Dinosalsa
Member
Registered: 2022-05-13
Posts: 15

[SOLVED]Add/eject USB devices resets keyboard remap to default configs

Greetings, I use a Colemak keyboard layout and have been experiencing a minor nuisance: the default keyboard configuration has the Caps Lock key working as a Backspace, while the original Backspace key still works as Backspace. In short, I have no Caps and two Backspaces (and I often need Caps). As a workaround, I've created a simple script that kicks in each time I log in that runs

xmodmap -e "keycode 66 = Caps_Lock"

and that's it.
Thing is, plugging USB devices in or out (external keyboard, a mouse, a printer, etc... flash drives are fine), my keyboard remapping is wiped and the Caps key goes back to working as Backspace.
I can simply run xmodmap...... again from the terminal, it takes seconds, so it doesn't ruin my day, but a definitive solution surely is within reach.
Now, I'm not a fan of creating new threads for problems that have been solved, so I've search around and eventually (necro)bumped this old, solved thread earlier today, which seemed to be a similar topic. While the thread is old, I thought it'd be more constructive to extend it a bit than starting another one. Alas, I've been instructed to start this new one, so I apologize for any disturbances there.
I already deleted my .config script and am bringing the outputs requested by seth on the other thread:
output for setxkbmap -print -query
output for xmodmap -pk | grep -Ei '(66|caps)'
and finally xev -event keyboard (and pressing the Caps key) before and after plugging in an USB mouse. I noticed I accidentally cut out the beginning of the output for before the plug in, but it's that "Outer window is...", so doesn't really change anything.

Finally, right now the key is remapped to work as Caps Lock.
Thanks in advance.

Last edited by Dinosalsa (2023-07-29 16:51:40)

Offline

#2 2023-07-28 21:39:18

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,119

Re: [SOLVED]Add/eject USB devices resets keyboard remap to default configs

http://ix.io/4BIX shows 66 being mapped to caps_lock?

us/colemak though indeed has

key <CAPS> { [    BackSpace,    BackSpace,       BackSpace,        BackSpace ] };

See whether

setxkbmap -option caps:capslock

gets you the "desired" behavior (caps acting as caps lock)

Offline

#3 2023-07-28 21:44:24

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,462
Website

Re: [SOLVED]Add/eject USB devices resets keyboard remap to default configs

If the above setxkbmap works, I'd suggest using the environment variable instead:

export XKB_DEFAULT_OPTIONS=caps:capslock

Just export that from your shell profile if you use start/xinit or from the relevant environment file if you use a DM.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Online

#4 2023-07-28 21:48:54

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,119

Re: [SOLVED]Add/eject USB devices resets keyboard remap to default configs

Or you add it to your xorg configlet for the relevant Section "InputClass"

Option		"XkbOptions" "caps:capslock"

Offline

#5 2023-07-29 15:20:28

Dinosalsa
Member
Registered: 2022-05-13
Posts: 15

Re: [SOLVED]Add/eject USB devices resets keyboard remap to default configs

Very well, an update:
Running

setxkbmap -option caps:capslock

does make the caps key work as Caps Lock. I can plug the mouse in an out freely and the setting doesn't change for the active session. However, when I plug in an external keyboard, the remapping is, once more, lost (for both keyboards). If I remap it and remove the external keyboard, the configuration isn't lost.

Also, I added

Option "XkbOptions" "caps:capslock"

to /etc/X11/xorg.config.d/00-keyboard.conf and, when that didn't work, even to /usr/share/X11/xorg.config.d/00-keyboard.conf (but that one more to keep my conscience clean) and logged out and rebooted a couple of times, but every time, when I log in, the key still works as Backspace so I have to remap it.
The contents of the config file are

Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        Option "XkbLayout" "us,br"
        Option "XkbModel" " "
        Option "XkbVariant" "colemak,"
        Option "XkbOptions" "grp:win_space_toggle" (This here switches the layout to Qwerty when someone else needs to use my laptop)
        Option "XkbOptions" "caps:capslock"
EndSection

I also tried running

export XKB_DEFAULT_OPTIONS=caps:capslock

from the terminal (was that where I was supposed to do it?), but it also didn't do the trick.
You guys are indeed up to something here. I digged a bit to find key codes to see if something was off, but it does indeed seem like "caps" should be working there

Edit: I was reading the wiki and even went to check the part about making changes to the keyboard. Out of curiosity, I went to /usr/share/kbd/keymaps/i386/colemak/colemak.map.gz and checked the list there. Key 66 (Caps) isn't listed there, but not all keys are anyway, most probably (I guess) because Colemak doesn't remap the whole keyboard

Last edited by Dinosalsa (2023-07-29 15:39:19)

Offline

#6 2023-07-29 15:26:24

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,119

Re: [SOLVED]Add/eject USB devices resets keyboard remap to default configs

Option "XkbOptions" "grp:win_space_toggle,caps:capslock"

I also tried running

export XKB_DEFAULT_OPTIONS=caps:capslock
from the termina

Trilby wrote:

Just export that from your shell profile if you use start/xinit or from the relevant environment file if you use a DM.

But I'm somewhat confident that a proper xorg configlet will cut it, the environment is mostly interesting if you don't have control over the server or want to discriminate clients.

Offline

#7 2023-07-29 15:58:54

Dinosalsa
Member
Registered: 2022-05-13
Posts: 15

Re: [SOLVED]Add/eject USB devices resets keyboard remap to default configs

OK, so I checked a bit more on the wikis, went to /etc/profile.d and, honestly, still can't make sense of it, but I also think that something should be achievable by adding a line to 00-keyboard.conf or something like that, but can't put my finger on it.

Offline

#8 2023-07-29 16:02:10

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,119

Re: [SOLVED]Add/eject USB devices resets keyboard remap to default configs

I also think that something should be achievable by adding a line to 00-keyboard.conf or something like that

Yes.  See my previous post.

Offline

#9 2023-07-29 16:36:23

Dinosalsa
Member
Registered: 2022-05-13
Posts: 15

Re: [SOLVED]Add/eject USB devices resets keyboard remap to default configs

I'm thinking about writing a new autosart script to run

setxkbmap -option caps:capslock

, since it works better than xmodmap, and adding a it udev rule to run the command again when an external keyboard is plugged in.
Something like this, maybe? But would it be possible to make that valid for any device rather than specifying an id/vendor?
I mean, this idea seems to make sense, but it may also add another layer of stuff that might go wrong

Offline

#10 2023-07-29 16:39:25

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,119

Re: [SOLVED]Add/eject USB devices resets keyboard remap to default configs

What exactly do you not understand about ther config line i posted in #6?

Offline

#11 2023-07-29 16:51:06

Dinosalsa
Member
Registered: 2022-05-13
Posts: 15

Re: [SOLVED]Add/eject USB devices resets keyboard remap to default configs

I don't understand how I missed it. Actually, I do. I thought you were quoting me and didn't notice the correction.
Just edited the configlet and logged in again and it's working As It ShOuLd with plugging in/removing the mouse. Now let's see with the keyboard.... AaAh, GoOd SiR, iT's AlIvE! I'll change edit the title to solved right away.
A summary for eventual future readers:
The issue was solved by editing file /etc/X11/xorg.conf.d/00-keyboard.conf and adding the line

Option "XkbOptions" "caps:capslock"

at the end. In my case, I already had another setting there (win_space_toggle), so in the end my line was Option "XkbOptions" "grp:win_space_toggle,caps:capslock"

Last edited by Dinosalsa (2023-07-29 16:57:18)

Offline

Board footer

Powered by FluxBB