Sample Header Ad - 728x90

Switching keyboard layouts

1 vote
3 answers
15354 views
**END GOAL** I use Arch Linux with bspwm as my window manager and sxhkd as a hotkey daemon. I want to map a certain key combination in my *sxhkdrc* so that it shuffles through different keyboard layouts. For example:
# Shuffle through keyboard layouts
super + e
    *action to be executed*
---------- **LOCALES** First, I do not know whether I am required to add Serbian locales as I only (from time to time) want to activate the Serbian keyboard layouts. My thinking is that keymaps are enough. Just in case, I generated Serbian locales; so now when I run localectl list-local, the output is:
en_US.UTF-8
sr_RS.UTF-8
sr_RS.UTF-8@latin
These respectively correspond to: - English locale for the U.S. – UTF-8 encoding - Serbian locale for Serbia – Cyrillic script – UTF-8 encoding - Serbian locale for Serbia – Latin script – UTF-8 encoding ---------- **KEYMAPS** The three layouts I want to use (be able to shuffle through) are: - us = US English - sr-cy = Serbian in Cyrillic script - sr-latin = Serbian in Latin script I know that I can edit /etc/vconsole.conf and set KEYMAP=sr_cy instead of us or use localectl set-keymap sr_cy. Here are my **concerns** with that: 1. It is not an elegant solution. 2. I cannot shuffle through different layouts. I have to run the command and specify the desired layout each time. 2. Would such change persists globally even after I log out or reboot the system? If the answer is yes, I will potentially be in trouble. I use LVM on LUKS encryption and for me to decrypt my disk I need us layout. Hence, if I forget to switch from Cyrillic script before rebooting, it's bye bye forever. ---------- **QUESTION** Is there any way for me to add multiple keymaps in /etc/vconsole.conf and have the us be the default one? If so, what do I need to do to switch between them. Is it a simple command or do I need a small script? If that is not an option, what is the best way to get to my end goal. I have tried finding the answer to having multiple keymaps but I was not able to find anything applicable to my problem. I would appreciate a solution or even advice and suggestions especially if it advances my knowledge. Thank you in advance!
Asked by Vladimir (219 rep)
May 20, 2022, 07:12 PM
Last activity: May 17, 2023, 11:50 AM