You are not logged in.

#1 2018-02-15 18:19:14

elric_ed
Member
From: Orlando, FL
Registered: 2012-02-21
Posts: 9

[SOLVED]Setting Keyboard options everytime a USB keyboard is connected

I have my Caps Lock key mapped to L_Control on my Keyboard.

To acheive this I used to have the following line at the end of my .i3/config file

exec --no-startup-id setxkbmap -option ctrl:nocaps

and it has worked well for me, so far.

Recently, I got a KVM switch to share the keyboard and mouse between my desktop and my laptop, however when I switch over to my laptop and back to my dekstop, the XkbOptions seems to have reset.

Is there someway to execute the setxkbmap command everytime a new keyboard is detected by the system (write a systemd unit file?)

I have tried adding the following two lines to my /etc/X11/xorg.conf file under the Keyboard InputDevice section, but still no luck

Option           "XkbLayout"  "us"
Option           "XkbOptions" "ctrl:nocaps"

Any suggestions?

Last edited by elric_ed (2018-02-16 04:15:44)

Offline

#2 2018-02-15 22:42:14

seth
Member
Registered: 2012-09-03
Posts: 51,325

Re: [SOLVED]Setting Keyboard options everytime a USB keyboard is connected

Why do you have a /etc/X11/xorg.conf file, what does it look like and please paste your xorg log.

Offline

#3 2018-02-16 04:14:57

elric_ed
Member
From: Orlando, FL
Registered: 2012-02-21
Posts: 9

Re: [SOLVED]Setting Keyboard options everytime a USB keyboard is connected

I had my xorg.conf file generated from nvidia-settings.

My xorg.conf file (with the issue) is here: https://pastebin.com/uMYn1Vna

I was able to solve the issue by changing my Keyboard section in the xorg.conf file as follows:

Section "InputClass"
    # generated from default
    Identifier       "Keyboard0"
    MatchIsKeyboard  "on"
    Driver           "kbd"
    Option           "XkbLayout"  "us"
    Option           "XkbOptions" "ctrl:nocaps"
EndSection

I had to set the MatchIsKeyboard option to "on"; and change the Section from "InputDevice" to "InputClass"

Now, Xorg behaves as expected!

Offline

#4 2018-02-16 07:27:52

seth
Member
Registered: 2012-09-03
Posts: 51,325

Re: [SOLVED]Setting Keyboard options everytime a USB keyboard is connected

You should not be using a static xorg.conf (deprecated, tends to cause trouble, easily breaks on HW changes) and especially not an auto-generated one because they tend to be full or crufty nonsense, like that keyboard section (I will just assume that you do not have xf86-input-keyboard installed and you should not because you most likely do not want to use it)

See https://wiki.archlinux.org/index.php/Xorg#Configuration
You most likey want some snippet in /etc/X11/xorg.conf.d/20-keyboard-layout.conf

Section "InputClass"
    Identifier       "keyboard_layout"
    MatchIsKeyboard  "on"
    Option           "XkbLayout"  "us"
    Option           "XkbOptions" "ctrl:nocaps"
EndSection

Offline

#5 2018-02-16 13:54:02

elric_ed
Member
From: Orlando, FL
Registered: 2012-02-21
Posts: 9

Re: [SOLVED]Setting Keyboard options everytime a USB keyboard is connected

Thank you seth!

I am working on splitting my xorg configurattion into multiple files in /etc/X11/xorg.conf.d/*.conf now

Offline

#6 2023-07-28 15:16:02

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

Re: [SOLVED]Setting Keyboard options everytime a USB keyboard is connected

Alright, I've found this here. I have a simple script in /.config that turns my Caps Lock into... Caps Lock automatically at login (I use a Colemak keyboard, and the default setting has the Caps key working as backspace, so I have 2 backspaces and no Caps): it simply runs

xmodmap -e "keycode 66 = Caps_Lock"

and that's it.
Now, when I plug in whatever other USB device, the settings go back to default. If I've understood what Seth said, I should also edit my 00-keyboard.conf file (here it's 00, not 20, but anyway...)
Seems fine enough. Now, I'm just not sure what kind of line I add there, because, you know, the key kind of is Caps, but is set as a backspace
Would it be something like Option "XkbOptions" "caps:nobackspace"?

Offline

#7 2023-07-28 15:33:27

seth
Member
Registered: 2012-09-03
Posts: 51,325

Re: [SOLVED]Setting Keyboard options everytime a USB keyboard is connected

Please don't necrobump w/ completely unrelated topics, your problem is that you don't like the colemak layout and/or (because I've no idea what that actually looks like) you're setting caps:backspace

Don't run that xmodmap script, what's the output of

setxkbmap -print -query
xmodmap -pk | grep -Ei '(66|caps)'
xev -event keyboard # now press the caps lock key

Last edited by seth (2023-07-28 15:33:39)

Offline

#8 2023-07-28 16:25:03

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,797

Re: [SOLVED]Setting Keyboard options everytime a USB keyboard is connected

Dinosalsa, I am going to close this five year old solved thread.  I invite you to start a new thread which you will own.  If you think this thread relevant, go ahead and link back to this thread.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

Board footer

Powered by FluxBB