Re: How can we change the keyboard layout? (was: what keyboard do you use?)
On Tue, 2024-02-06 at 01:37 -0500, Brian Sammon wrote:
> On Mon, 05 Feb 2024 21:06:30 +0100
> hw <hw@adminart.net> wrote:
>
> > Yes, it's a misunderstanding: How can we change the keyboard layout?
>
> I recently dug into this because I am running Debian on a
> Chromebook, and I wanted to map the Google-key (located next to the
> A key, where you usually expect Caps-Lock to be) to be a Ctrl, for
> Emacs-Correctness. I wanted a solution that would also work when I
> used an external keyboard (which has an actual CapsLock next to the
> A), and would work both in X and in console mode.
Wow that's a very tall order!
> The solution I found, which should work when using Wayland as well,
> was to customize the lowlevel scancode-to-keycode mapping that is
> managed by udev. You can have different remappings for different
> keyboard models.
>
> This keymapping system is very powerful, but somewhat ideosyncratic,
> and somewhat poorly documented.
At least there is a way :)
Have you been able to find the predefined keyboard layouts that can be
selected through gnome (or KDE) settings somewhere? I was thinking if
I could find those, I might be able to make a copy of one and then
modify it they way I need it. Or is that approach not even feasible?
I think I rather don't want to change the scancode-to-keycode mapping
but would want to change the keycode-to-key mapping like it's done
with xmodmap.
> And it's an edit-the-configfile system; I'm not aware of any GUI
> config tools for it.
Well, I prefer that.
> Some of the webpages in my notes that I remember being useful are:
> https://wiki.archlinux.org/title/Keyboard_input
Hmm, that gives me wev to start with, as the equivalent of xev.
Is wayland using this XKB thing? When I run 'setxkbmap -print
-verbose 10' I'm getting 'WARNING: Running setxkbmap against an
Xwayland server'. Does that mean we're not supposed to do that and/or
that we're not supposed to use XKB?
> https://yulistic.gitlab.io/2017/12/linux-keymapping-with-udev-hwdb/ (including some of the comments that contain more recent info)
> https://medium.com/@canadaduane/key-remapping-in-linux-2021-edition-47320999d2aa
>
> Some somewhat-informative files on my computer were
> /lib/udev/hwdb.d/60-keyboard.hwdb (comes with udev)
That's an interesting file indeed!
So I want to change that I have to press Shift+` to get a tilde to not
having to press Shift. I. e. the key is the first key on top row of
my keyboard and has ` and ~ on it, and I want to just press it and get
a tilde.
Wev says 'key: 49'. That is 0x31 which doesn't show up in this file.
Now what?
> /usr/include/linux/input-event-codes.h (comes with linux-libc-dev package)
According to that, 49 is KEY_N and 'tilde' doesn't exist.
> Gotchas include:
> Some things *must* be in lowercase (keycodes, I think?)
> Some things *must* be in uppercase (certain hexadecimal stuff?)
Yeah it says something about that in the comments in 60-keyboard.hwdb.
> For best results, triple-check that the case you use is exactly the
> same as the example/sample config files.
It seems to me that 60-keyboard.hwdb is intended to provide certain
keycodes --- i. e. symbols understood by the kernel since they seem to
show up in input-event-codes.h --- for a bunch of different keyboards.
That seems like the case Loris described with a laptop. Perhaps he
would need to specify some (evdev) identifier for that particular
keyboard in 60-keyboard.hwdb, along with a mapping for the scancode
and the symbol --- and then somehow make a pull request or bug report
as described in the file. Then these keys may end up working for
everyone with such a laptop.
> If you get this wrong, udev will just ignore the erroneous parts of
> your config file, (and you might think it just didn't see it)
> instead of giving an error message.
Hm, that's bad ...
Still I think this the wrong place to make changes for my case. I
could try something with my keyboard, but I don't understand these
evdev designations in 60-keyboard.hwdb, so I won't even be able to
specify my keyboard to make settings for it.
Reply to: