[SOLVED]Changing keyboard layout in console

Kernels & Hardware, configuring network, installing services

[SOLVED]Changing keyboard layout in console

Postby pythagorasmk » 2020-02-12 02:57

Is it possible to have multiply keyboard layouts in console and to have key combination to switch between them?
Last edited by pythagorasmk on 2020-02-13 18:19, edited 1 time in total.
pythagorasmk
 
Posts: 114
Joined: 2015-01-18 03:40

Re: Changing keyboard layout in console

Postby Head_on_a_Stick » 2020-02-12 05:20

Not really (AFAIK), but you can use localectl(1) to change console keyboard layout.

Perhaps if you ran dvtm (or plain tmux) from the console you could bind keys calling that command.

EDIT: corrected command name.
Last edited by Head_on_a_Stick on 2020-02-12 17:09, edited 1 time in total.
Black Lives Matter

Debian buster-backports ISO image: for new hardware support
User avatar
Head_on_a_Stick
 
Posts: 12809
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Changing keyboard layout in console

Postby fabien » 2020-02-12 13:44

It is possible to use loadkeys(1) to change keyboard layout on the fly (i.e. without changing system configuration):

- package console-data must be installed

- you have to allow your user to use loadkeys (see https://unix.stackexchange.com/questions/85374/loadkeys-gives-permission-denied-for-normal-user)

- there may be security concerns (that's why loadkeys doesn't work if not setuid, see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0b360adbdb54d5b98b78d57ba0916bc4b8871968) so all in all be aware that it might not be good practice.
User avatar
fabien
 
Posts: 15
Joined: 2019-12-03 12:51
Location: Toulouse, France

Re: Changing keyboard layout in console

Postby pythagorasmk » 2020-02-13 18:18

I am giving up, security risk + to complicated, not for me. Anyway Thanks for the answer.
pythagorasmk
 
Posts: 114
Joined: 2015-01-18 03:40

Re: Changing keyboard layout in console

Postby pythagorasmk » 2020-02-14 15:39

fabien wrote:It is possible to use loadkeys(1) to change keyboard layout on the fly (i.e. without changing system configuration):

I have found package console-setup and with it you can have the same options for keyboard on console, as in Xserver. The default configuration is located in /etc/default/keyboard. Read keyboard(5).
pythagorasmk
 
Posts: 114
Joined: 2015-01-18 03:40

Re: [SOLVED]Changing keyboard layout in console

Postby fabien » 2020-02-15 00:04

This is the right solution, thanks pythagorasmk. The loadkeys method is definitely to be forgotten then (it was an old remembrance btw, something I used long ago).

Here is the documentation on Debian Wiki: https://wiki.debian.org/Keyboard

Code: Select all
man 7 xkeyboard-config

is useful to find some configuration elements (layouts, switches) for /etc/default/keyboard.

In short:
- edit /etc/default/keyboard. For example:
Code: Select all
# KEYBOARD CONFIGURATION FILE

# Consult the keyboard(5) manual page. man xkeyboard-config(7) also.

XKBMODEL="pc105"
XKBLAYOUT="fr,us"
XKBVARIANT="latin9,"
XKBOPTIONS="grp:alts_toggle"

BACKSPACE="guess"

this configuration allows to switch between french and US layouts by striking alt and altgr together.

- from the console, test the configuration:
Code: Select all
setupcon

- make changes permanent (this part is not on the Debian Wiki but it is the only way that worked for me):
Code: Select all
dpkg-reconfigure console-setup
User avatar
fabien
 
Posts: 15
Joined: 2019-12-03 12:51
Location: Toulouse, France

Re: [SOLVED]Changing keyboard layout in console

Postby pythagorasmk » 2020-02-15 02:28

fabien wrote:- make changes permanent (this part is not on the Debian Wiki but it is the only way that worked for me):
Code: Select all
dpkg-reconfigure console-setup

You can edit the file /etc/default/console-setup directly, there is no need for dpkg-reconfigure console-setup. Read console-setup(5).
The only limitation for me is that accented letters in Macedonian alphabet ( ѐ and ѝ ) and the symbol for euro € are missing in fonts for console.
Also, if you are using Emacs, it is not smart to use left alt + left shift (standard Windows combination ) for switch key, I have assigned this function to ScrollLock.
pythagorasmk
 
Posts: 114
Joined: 2015-01-18 03:40

Re: [SOLVED]Changing keyboard layout in console

Postby fabien » 2020-02-15 09:49

pythagorasmk wrote:You can edit the file /etc/default/console-setup directly, there is no need for dpkg-reconfigure console-setup. Read console-setup(5).

dpkg-reconfigure console-setup is the way I found to make changes permanent, otherwise changes were lost upon reboot (I'm on Buster). Have you done something else to keep changes effective?
I know I can edit /etc/default/console-setup directly, I added BEEP="polite" to it to no avail until I run dpkg-reconfigure console-setup. There should be a smarter way though, I agree.

pythagorasmk wrote: it is not smart to use left alt + left shift

I use alt+altgr in the example above, but that's up to the user (man 7 xkeyboard-config for a list of available switches).

pythagorasmk wrote:( ѐ and ѝ ) and the symbol for euro € are missing

take a look at section 'Adding currency signs to certain keys' in man 7 xkeyboard-config maybe. For the Macedonian alphabet I have no clue.
User avatar
fabien
 
Posts: 15
Joined: 2019-12-03 12:51
Location: Toulouse, France

Re: [SOLVED]Changing keyboard layout in console

Postby pythagorasmk » 2020-02-15 11:27

fabien wrote:dpkg-reconfigure console-setup is the way I found to make changes permanent, otherwise changes were lost upon reboot (I'm on Buster). Have you done something else to keep changes effective?

For me everything is working fine, I have edited the console-setup with emacs, saved the file, rebooted the system and everything is working fine. I am also on Debian Buster.

fabien wrote:I use alt+altgr in the example above, but that's up to the user (man 7 xkeyboard-config for a list of available switches).

Yes it is up to the user, but left alt+left shift is useful combination in Emacs.

fabian wrote:take a look at section 'Adding currency signs to certain keys' in man 7 xkeyboard-config maybe. For the Macedonian alphabet I have no clue.

Yes, I can add the euro sign to some key, but I have to use 3-level chooser, which cannot be pause, scroll lock or prtscr and I don't want to use ctrl or alt for that. I can live with that. It is interesting that I can get euro sign in Xserver with Compose key and after that e and =, but this combination is not working in console, and I don't know why? For macedonian symbols, I think that they are missing in fonts files for console, because the deadkey is working in console. I think that this is a long time bug, and nobody is taking care of it.
It is interesting that PtrScr is not working as a compose key in console, but it is working in Xserver. I don't know why? I think this is a bug.
pythagorasmk
 
Posts: 114
Joined: 2015-01-18 03:40


Return to System configuration

Who is online

Users browsing this forum: No registered users and 30 guests

fashionable