Name of detect keyboard layout tool
This tool will show your current layout graphically:
gkbd-keyboard-display -g 1
This is the command used during setup for choosing your keyboard layout:
dpkg-reconfigure keyboard-configuration
But to make it auto-detect the keyboard, you need to change a setting in dpkg-reconfigure keyboard-configuration
. I'm not sure what setting, though.
To change a setting, echo <packagename> <setting> <type> <value> | debconf-set-selections
. For example:
echo "keyboard-configuration console-setup/ask_detect boolean true" | debconf-set-selections
Hopefully this helps you.
The program used to detect keyboard layout during Ubuntu installation is part of the ubuntu installer called "Ubiquity".
You can find the source code on the Launchpad project page or download the release used in your Ubuntu version using
apt-get source ubiquity
You can navigate in the code here: https://git.launchpad.net/ubuntu/+source/ubiquity/tree/?h=ubuntu/bionic-devel
The GTK GUI definition with the button "Detect Keyboard Layout" is here: https://git.launchpad.net/ubuntu/+source/ubiquity/tree/gui/gtk/stepKeyboardConf.ui Search for 'Detect Keyboard Layout', you will find 'deduce_layout'
I'm not 100% sure but I think the code that does the keyboard detection is here: https://git.launchpad.net/ubuntu/+source/ubiquity/tree/ubiquity/plugins/ubi-console-setup.py Search for 'deduce_layout', you will find 'calculate_keymap_button' (calculate_clicked), etc.
And here: https://git.launchpad.net/ubuntu/+source/ubiquity/tree/ubiquity/frontend/gtk_components/keyboard_query.py Search for 'ubiquity/text/keyboard_query_title'.
See also this webpage for easier navigation in the code: http://nullege.com/codes/search/ubiquity.keyboard_detector.KeyboardDetector
I hope it helps.
Install the console-data
package.
sudo apt-get install console-data
Then run this command on the terminal:
sudo dpkg-reconfigure console-data
It will then allow you to change the keyboard layout.