Whenever I plug in a USB keyboard, the layout of all keyboards is reset to some system default (a US layout which doesn't have modifiers and other keys the way I want them). I've observed this on many Debian and Ubuntu systems, including Ubuntu 16.04 and 18.04. This behavior has been around for a very long time.
I use X11 with no desktop environment (though some Gnome demons tend to get started). I set my keyboard layout with XKB (specifically
… | xkbcomp - "$DISPLAY") when I log in.
When I insert a USB keyboard, I want it to have my layout, not the system layout. In fact, I wish the system would just keep using my current layout for both the already present keyboard(s) if any, and the newly inserted keyboard. If that's not possible, I'd settle for re-applying a layout that I chose.
Likewise the repeat rate on both keyboards is set to the login-time default instead of the rate I set with
How can I prevent a keyboard hotplug from resetting the keyboard layout and the repeat rate? Or failing that how can I at least make it reset to my chosen layout?
There's a fairly clumsy way which is with a udev rule. It's clumsy because it assumes that there's a single X server, and most problematically, it assumes that the user has root permission. I do not have root permissions, so any method that involves setting udev rules or editing
Xorg.conf is inapplicable here.